Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  
Yancka

Determine if point lies on selected polygon

Recommended Posts

Howdy gents,

is there a way how to determine if point (X,Y given) lies on pre-selected polygon (polyline, line) or even on multiple of those? Or lies in certain distance (tolerance offset) from those pre-selected linear objects?

Share this post


Link to post

Miguel,

Doesn't this just tell you if the point is inside the area of the polygon? Do you know a trick to make it return only objects that are actually on the line?

Share this post


Link to post

Yes, I know a way but involves a bit more work.

You can use:

PROCEDURE LineLineIntersection( l1start :POINT;

l1end :POINT;

l2start :POINT;

l2end :POINT;

VAR parallel :BOOLEAN;

VAR intOnLines:BOOLEAN;

VAR sectpt :POINT);

line1 is the segment between two vertices of the polygon.

line2 is a line perpendicular to the segment passing through the point in question.

intOnlines will return true if the intersecting point is on the polygon line segment.

Or you can test for distance with the resulting sectpt if within a tolerance factor.

Before this procedure was added, I calculated the distance from the intersecting point to each end of the line segment. If the sum of the 2 distances equaled the length of the line segment then the point was on the line.

Share this post


Link to post

By the way, according to the definition of PtInPoly, all points within or on the polygon will return true.

My understanding is that "on the polygon" means on a line segment of the polygon.

Share this post


Link to post

There is also this function:

PtOnLine(Pt, BegPt, EndPt: VECTOR; Tolerance: REAL) : BOOLEAN;

Use it in a loop for each side of your Poly.

Raymond

Share this post


Link to post
There is also this function:

PtOnLine(Pt, BegPt, EndPt: VECTOR; Tolerance: REAL) : BOOLEAN;

Thanks Raymond, sounds promising!

rrrrr...... this function isn't documented in VW function reference

Share this post


Link to post

This one's an easy one to guess. By trial usage I determined the following:

PtOnLine returns TRUE if point Pt is on the line segment defined between points BegPt and EndPt, inclusive; or within a distance, defined by Tolerance, of that line segment. Otherwise it returns FALSE.

Pt = point to be tested, stored as a vector (Pt.x, Pt.y, Pt.z)

BegPt = first point of line segment, stored as a vector (BegPt.x, BegPt.y, BegPt.z)

EndPt = second point of line segment, stored as a vector (EndPt.x, EndPt.y, EndPt.z)

Notes:

1) For 2D lines and points, the z component of the three vectors is 0.

2) Because of the nature of real numbers stored in computers, Tolerance should not be set to 0. Make it a suitably small number for your use. 1e-6 or 1e-9 should work for most architectural needs. Anything greater than 1e-323 will work for the number system employed by VW (at least as I've tested it on a Mac).

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×