.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Point on line

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
gulzar25
1026 Views, 8 Replies

Point on line

Hi,

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

 

Thanks

Gulzar

8 REPLIES 8
Message 2 of 9

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

}

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 9
gulzar25
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

 

Message 4 of 9

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
 
[assemblyCommandClass(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: ");
      peOpt.SetRejectMessage("\nMust be Curve!");  peOpt.AddAllowedClass(typeof(Curve), false);
      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");
          }
        }
      }
    }
  }
}

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 9

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

Message 6 of 9

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

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 7 of 9

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

Message 8 of 9

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.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 9 of 9
mzakiralam
in reply to: gulzar25

if your problem is not solved yet , you can go through this article. I hope this will solve your problem.

 

http://through-the-interface.typepad.com/through_the_interface/2012/01/testing-whether-a-point-is-on...

 

Regards

Zakir

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost