[MWForum]Calling mathcats: geometry help please

Daniel Ajoy mwforum@lists.mathcats.com
Wed, 11 Aug 2004 21:57:22 -0500


On 11 Aug 2004 at 17:41, Jeff Knope wrote:

> Hi ~
> 
> I just fired up OE to write this. But in comes Daniel and 
> Wendy's discussion of the Reference Card. Wow! You took me 
> seriously? Just kidding. I haven't gone to the PDF yet, but 
> as soon as I get the following off my chest I will.
> 
> I need some help writing (or finding) a MW algorithm for 
> Intersection of 2 lines. The input list is likely of a form 
> similar to this: [[[x1 y1][x2 y2]] [[x3 y3][x4 y4]]], where 
> 1's and 2's are a pair of points on a line; and 3's and 4's 
> are a pair of points on another (non-parallel) line. The 
> output is the "shared point" - or intersection.
> 
> Googling around, there appear to be a few ways to go about 
> it. The most simple and direct of them appears to be the 
> algebraic solution of 2 simultaneous equations. Trouble is, 
> as I examine my own (weak) processes for doing that, I find 
> I'm doing lots of visual scanning for opportunities to 
> algebraically reduce the expressions. It's a kind of 
> intuitive process I haven't the faintest idea how to reduce 
> MW procedures.
> 
> Maybe that's why there's those more esoteric approaches. 
> Anyway, this is a common function. Most any CAD program has 
> it working in one way or another in many different commands.
> 
> So who better to ask than the mathcats?
> 
> Thank you, --Jeff
> 
> 

This seems to work (it's my code, all the bugs too :)

to inter :l
make "x1 first first first :l
make "y1 last first first :l
make "x2 first last first :l
make "y2 last last first :l
make "x3 first first last :l
make "y3 last first last :l
make "x4 first last last :l
make "y4 last last last :l

make "d1x :x1 - :x2
make "d1y :y1 - :y2
make "d2x :x3 - :x4
make "d2y :y3 - :y4

make "x1x :x2
make "x1y :y2
make "x2x :x4
make "x2y :y4

make "c :d1x * :d2y - :d1y * :d2x
if :c = 0 [output "PARALLEL]

make "t1 (:d2x * (:x1y - :x2y) + :d2y * (:x2x - :x1x)) / :c

if or :t1 > 1 :t1 < 0 [output "NOTAVAILABLE]
output list (:x1x + :d1x * :t1) (:x1y + :d1y * :t1)
end


Daniel
OpenWorld Learning (OWL)
http://mia.openworldlearning.org