.NET

## .NET

Active Contributor
Posts: 42
Registered: ‎07-02-2013
Message 1 of 9 (332 Views)

# Point on line

332 Views, 8 Replies
07-09-2013 04:52 AM

Hi,

Is there any function available to find out if a point is present on a line or not?Please help.

Thanks

Gulzar

Regards

Zakir

Moderator
Posts: 1,417
Registered: ‎04-09-2008
Message 2 of 9 (326 Views)

# Re: Point on line

07-09-2013 05:47 AM in reply to: gulzar25
```Point3d p; // Given point

Curve crv; // Given curve, eg. Line, Polyline, Circle, etc...

Point3d pNear = crv.GetClosestPointTo(p);

if (pNear.DistanceTo(p) < Tolerance.Global.EqualPoint)
{

// Point is on Curve

}```

Пожалуйста не забывайте про Утвердить в качестве решения и Баллы
Please remember to Accept as Solution and Kudos

Active Contributor
Posts: 42
Registered: ‎07-02-2013
Message 3 of 9 (281 Views)

# Re: Point on line

07-09-2013 08:57 PM in reply to: gulzar25

Hi Alexander,

Thankyou so much for the reply but if i declare pNear as Point3d, GetClosestPointTo() function doesnt accept as it returns PointOnCurve3d and if i declare pNear as Point3d i cant access DistanceTo() function.Kindly help.

Thanks

Gulzar

Moderator
Posts: 1,417
Registered: ‎04-09-2008
Message 4 of 9 (273 Views)

# Re: Point on line

07-09-2013 10:39 PM in reply to: gulzar25
```using System;

[assembly: CommandClass(typeof(Rivilis.CurveUtils))]

namespace Rivilis
{
public class CurveUtils
{
[CommandMethod("PointOnCurve")]
public void MyCommand() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;

PromptEntityOptions peOpt = new PromptEntityOptions("\nSelect curve: ");
PromptEntityResult peRes = ed.GetEntity(peOpt);
if (peRes.Status != PromptStatus.OK) return;

PromptPointResult ppRes = ed.GetPoint("\bPick point: ");
if (ppRes.Status != PromptStatus.OK) return;

Point3d p = ppRes.Value.TransformBy(ed.CurrentUserCoordinateSystem);

using (Transaction tr = doc.TransactionManager.StartTransaction()) {

Curve crv = tr.GetObject(peRes.ObjectId, OpenMode.ForRead) as Curve;
if (crv != null) {
Point3d pNear = crv.GetClosestPointTo(p, false);
if (pNear.DistanceTo(p) < Tolerance.Global.EqualPoint) {
ed.WriteMessage("\nPoint is on Curve");
} else {
ed.WriteMessage("\nPoint is not on Curve");
}
}
}
}
}
}
```

Пожалуйста не забывайте про Утвердить в качестве решения и Баллы
Please remember to Accept as Solution and Kudos

Active Contributor
Posts: 42
Registered: ‎07-02-2013
Message 5 of 9 (273 Views)

# Re: Point on line

07-09-2013 10:39 PM in reply to: Alexander.Rivilis

Hi,

If i have 2 points on the same line the code is working fine for 1 point and for the other point it is not satisfying the condition ("if (pNear.DistanceTo(p) < Tolerance.Global.EqualPoint)") even though the second point is on the given line.I am not able to figure out why this is happening.I will be grateful for replies.

Thanks Gulzar

Moderator
Posts: 1,417
Registered: ‎04-09-2008
Message 6 of 9 (260 Views)

# Re: Point on line

07-10-2013 12:27 AM in reply to: gulzar25

Ok! You can replace in code Tolerance.Global.EqualPoint with 0.001 (or other small value).

Пожалуйста не забывайте про Утвердить в качестве решения и Баллы
Please remember to Accept as Solution and Kudos

Active Contributor
Posts: 42
Registered: ‎07-02-2013
Message 7 of 9 (255 Views)

# Re: Point on line

07-10-2013 12:35 AM in reply to: Alexander.Rivilis

Hi Alexander,

Thanks for the reply.What i meant when i said that it is not satisfying the condition ("(pNear.DistanceTo(p) < Tolerance.Global.EqualPoint)") is distance is coming greater than tolerance value(for example 100).Even though the point is on the line for which im checking.I dont know why this is happening.

Thanks

Gulzar

Moderator
Posts: 1,417
Registered: ‎04-09-2008
Message 8 of 9 (246 Views)

# Re: Point on line

07-10-2013 01:58 AM in reply to: gulzar25

I think the line and a point are in 3D. Double check the coordinates of the given point and the nearest point on the line.

Пожалуйста не забывайте про Утвердить в качестве решения и Баллы
Please remember to Accept as Solution and Kudos

Mentor
Posts: 231
Registered: ‎11-09-2012
Message 9 of 9 (219 Views)

# Re: Point on line

07-11-2013 07:33 AM in reply to: gulzar25

Regards

Zakir

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.