Parallel Lines coordinate

Parallel Lines coordinate

fsl88
Contributor Contributor
466 Views
1 Reply
Message 1 of 2

Parallel Lines coordinate

fsl88
Contributor
Contributor

I there a code for knowing the 2 coordinates as shown below. x1,y1 and x2,y2 are known coordinates, offset distance is also known. The two lines are equal in length. Thanks.

fsl88_0-1653129914380.png

 

0 Likes
Accepted solutions (1)
467 Views
1 Reply
Reply (1)
Message 2 of 2

_gile
Consultant
Consultant
Accepted solution

Hi,

 

You can use some simple vector calculus using APIs from the Geometry namespace (GetVectorTo, GetPerpendicularVector, GetNormal).

 

    var pt1 = new Point2d(x1, y1);
    var pt2 = new Point2d(x2, y2);

    // Get the vector from pt1 to pt2
    var direction = pt1.GetVectorTo(pt2);

    // Get the perpendiclar vector to direction with a length of 'offsetDistance'
    var perpendicularVector = 
        direction.GetPerpendicularVector().GetNormal() * offsetDistance;

    // Offset pt1 and pt2 (substracting the vector to offset to right)
    var offsetPt1 = pt1 - perpendicularVector;
    var offsetPt2 = pt2 - perpendicularVector;

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes