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

How to determine a point on one line

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
HelloWorlddd
622 Views, 4 Replies

How to determine a point on one line

For example:
pt(0,0,0) is on the line((1,-1,0),(-1,1,0)
then I will get true


pt(1,2,3) is not on the line((1,-1,0),(-1,1,0)
then I will get false

 

Is there exist some method that I can use?

An example will be better. Very Thanks

4 REPLIES 4
Message 2 of 5
_gile
in reply to: HelloWorlddd

Hi,

 

You can try this overloaded Isinside method;.

 

        private bool IsInside(Line line, Point3d point)
        {
            return IsInside(line.StartPoint, line.EndPoint, point);
        }

        private bool IsInside(LineSegment3d line, Point3d point)
        {
            return IsInside(line.StartPoint, line.EndPoint, point);
        }

        private bool IsInside(Point3d start, Point3d end, Point3d point)
        {
            Vector3d v1 = start.GetVectorTo(point);
            if (v1.IsEqualTo(new Vector3d()))
                return true;
            Vector3d v2 = start.GetVectorTo(end);
            return 
                v1.IsCodirectionalTo(v2) && 
                0.0 <= v1.Length && 
                v1.Length <= v2.Length;
        }

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 5
cdinten
in reply to: HelloWorlddd

one way is using Curve3d.IsOn() method, it has 6 overload version, you can choose one, this is the general approach

 

when it comes to Line, another way is using Point3d.GetDistanceTo()

a Line has StartPoint and EndPoint,abbr sp & ep.

if you want to check Point3d p, then:

d1=p.GetDistanceTo(sp);

d2=p.GetDistanceTo(ep);

length=theLine.Length;

if

A:d1+d2==length

or

B:|d1-d2|=length

thus we assume p is on the line,case A means p is on the line, case B means p on the extend, see image below:

CX_0331_110831.jpg

Message 4 of 5
HelloWorlddd
in reply to: cdinten

Thank you very much, it's a easy way.
Message 5 of 5
cdinten
in reply to: HelloWorlddd

it should be. it is both easy to understand in mathematics and to convert this idea to code.

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