Unfortnately, Bill's method will prevent a large number of legitimate lines
from being tested.   However, if you apply vectors and analytic geometry a
little further, you can get a more robust solution.  

There is an operation on two-dimensional vectors called the "slash product",
a two-dimensional analogue of the more familiar cross product.  Given two
vectors a and b,

a / b = dx_b * dy_a - dy_b * dx_a 

where dx_a is the scalar component of vector a along the x-axis.

The slash product returns a scalar which is equal to 

a / b = |a||b| sin h

where h is the angle between the two vectors.  Thus, if you
calculate a/b and it comes out as 0, either the lines are
parallel or one of the lines is degenerate. 

If you apply this when the coordinates are represented in a conformal
projection, you will approximate the spherical case very closely over short
distances.  Slight modifications can get you the actual point of
intersection, or whether the lines are coincident rather than merely
parallel.

Hope this helps
Spencer



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Bill Thoen
Sent: Monday, June 26, 2006 9:51 AM
To: Colin Henderson
Cc: [email protected]
Subject: Re: [MI-L] MI-L: Checking if two lines are parallel

Colin Henderson wrote:

> Does anyone know how I can check if two lines are parallel in 
> MapBasic? I can't find a function that provides this information so I 
> presume I'm going to have to code a function to perform the check.  
> Any ideas what this function may look like? I'm presuming I'm going to 
> need to compare the angle and direction of the two lines, is this so
>
The spherical case is a little more interesting, but in the cartesian 
case if two lines have the same slope, they are parallel. That is, if 
your first line has coordinates x1,y1 and x2, y2 and your second's are 
x3,y3 and x4,y4, then (y2-y1)/(x2-x1) = (y4-y3)/(x4-x3). Also, you 
should first check to make sure that (x2-x1) <> 0 and that (x4-x3) <> 0.


_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to