Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #3737

The intersect function

Newsgroups comp.lang.postscript
Date 2022-01-24 09:45 -0800
Message-ID <2ce10882-a3bb-44da-b921-30a41b2492d7n@googlegroups.com> (permalink)
Subject The intersect function
From luser droog <luser.droog@gmail.com>

Show all headers | View raw


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 }

Back to comp.lang.postscript | Previous | Next | Find similar


Thread

The intersect function luser droog <luser.droog@gmail.com> - 2022-01-24 09:45 -0800

csiph-web