Scott,

> I've got a graphical application with four basic items.
> - a single point object
> - a two point object (line segment)
> - a three point object (arc)
> - a multi point object (polygon)
>
> The user can select any two items and have the system calculate the 
> distance
> between them.  Each type of comparison has its own function so the code 
> looks
> something like this [snip]
> I[s] there a better way to do this kind of comparison?

I would collapse the point, line segment, and polygon into one item: a 
polygon.  After all, a point is a polygon with one vertex, a line segment is 
a polygon with two vertices, and a traditional polygon has three or more 
vertices.  You could do this "collapsing" at the fundamental level, where 
the point is stored exactly as a single-vertex polygon.  You could also do 
the collapsing at the start of the distance function: copy a point into a 
single-vertex polygon, and so on.

You just need to make sure that your algorithm that calculates the distance 
from a point to a line segment is general enough to handle a zero-length 
line segment.  That is not hard: I have done it.  This algorithm is used to 
calculate the distance between any two of the "polygons."

This results in only four cases: polygon to polygon, arc to polygon, polgyon 
to arc, and arc to arc.  I don't see any easy way to collapse this further, 
although if I had enough time I might be able to do so.

Does this help?  Ask if you want my point-to-line-segment distance routine.

Rory Daulton
[EMAIL PROTECTED] 


-------------------------------------------------------------------------------
[This e-mail scanned for viruses and spam by Nmax - "Your MAXimum Connection!"]

__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to