The intersect function

9 views
Skip to first unread message

luser droog

unread,
Jan 24, 2022, 12:45:47 PMJan 24
to
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 https://www.ntg.nl/maps/18/23.pdf
/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
Forward
0 new messages