TheSwamp

Code Red => .NET => Topic started by: huiz on July 11, 2013, 05:23:43 AM

Title: On which side of a polyline?
Post by: huiz on July 11, 2013, 05:23:43 AM
Is it possible to check on which side of a selected polyline a given point is?

I can check the closest point on the polyline and get the distance between the given point and the closest (perpendicular) point on the polyline but that distance value is always positive. I would like a negative disance if the point is on the left-hand side and positive on the right-hand side.
Title: Re: On which side of a polyline?
Post by: bargool on July 11, 2013, 05:34:20 AM
You can get closest point on polyline
Method GetClosestPointTo of the polyline object. Then use vectors etc..
Title: Re: On which side of a polyline?
Post by: gile on July 11, 2013, 06:05:08 AM
Hi,

Here's a little extension method which strictly checks for left or right.

Code - C#: [Select]
  1.     public static class PolylineExtension
  2.     {
  3.         public static double GetSignedDistanceTo(this Polyline pline, Point3d pt)
  4.         {
  5.             Point3d closest = pline.GetClosestPointTo(pt, false);
  6.             Vector3d deriv = pline.GetFirstDerivative(pline.GetParameterAtPoint(closest));
  7.             return deriv.GetAngleTo(closest.GetVectorTo(pt), pline.Normal) > Math.PI ?
  8.                 pt.DistanceTo(closest) : -pt.DistanceTo(closest);
  9.         }
  10.     }

If the issue is about polyline offset side, you can see this reply (http://www.theswamp.org/index.php?topic=31862.msg494503#msg494503) and the related following ones.
Title: Re: On which side of a polyline?
Post by: huiz on July 11, 2013, 07:07:35 AM
Really cool Gile!  :)

I was thinking in more complex solutions but I did learn again from your code! Thank you :-)