The intersect function

Skip to first unread message

luser droog

Jan 24, 2022, 12:45:47 PMJan 24
I kinda buried the lead in the star drawing program. After years of struggling
to write this function in many clumsy ways. Finally, a super short
implementation that's truly mind boggling. I only made some syntax changes.

It takes 4 points `a b c d` (each a 2 element array) and yields
a 2 element array of the intersection point (a->b)x(c->d). The source
mentions some cases where the function fails. Presumably this
is when one of the 3 intermediate matrices is not invertible (like if
they don't intersect, maybe?).

% intersect adapted from
/intersect { aload pop
1 dict begin {d c b a}{exch def}forall
1 1
1 1 [a _x b _x a _y b _y 0 0] itransform % A B
1 1 [c _x d _x c _y d _y 0 0] itransform % A B C D
0 0 6 array astore
itransform 2 array astore
end }
/_x { 0 get }
/_y { 1 get }
Reply all
Reply to author
0 new messages