Drawing a line in an angle (C#)

Hi Guys,
I am trying to draw a line in an angle (perpendicular to the line it’s starting from). Below is an example of what I am trying to achieve. In the below example the left line is drawn off the dotted line, it is perpendicular to the dotted line.

In my c# code I have the following

doc.Objects.AddLine(new Line(topInterL, new Point3d(topInterL.X - (90 - topAngle), topInterL.Y + perimeterOffset, 0)));

topInterL - it holds the point of intersection between the folded line and the line am trying to draw.
topAngle - The angle of the folded line

Hope you can understand what I have already done, I am just getting the ‘X’ value of the intersection point and then reducing it by the calculated angle. However, this approach is not working for me.
What I am doing wrong here?

Regards,
Wil

well the X value of the intersection point is a coordinate and reducing this by 90 degrees I’m not sure what you are trying to achieve.

It looks like your lines are in 2d space only? of so you can write a simple function to rotate vectors 90 degrees counter-clockwise:

    public static Vector3d RotateVector90DegreesCCW(Line line)
    {
        return new Vector3d(-Line.Direction.Y, Line.Direction.X, 0);
    }

and then you can create your new line:

    public static Line CreateNewLineFromIntersection(Line line, Point3d intersectionPoint, double length)
    {
        Vector3d newDirection = RotateVector90DegreesCCW(Line line);
        return new Line(intersectionPoint, newDirection, length);
    }

I just wrote this down here so there might be typos.

1 Like

Hi Thank you for the reply. Unfortunately , the solution what you have provided is not what I am a looking for.
Let me make it more simple, am looking for a solution to draw a line in an angle but in C# coding.
Say user provides input as 70 degree, I want to draw a line from a point eg:- 0,0,0 but in the angle which user has provided.

So it’s still in 2d? What is the desired behaviour if the user specifies 0 or 90 degrees? I presume world x axis to be corrosponsing to 0 degrees here:

Assume Point3d startPoint pt0 and double rotationAngle as given user inputs, then this is one way of doing it with fhinocommon methods.

Plane helperPlane = new Plane(Plane.WorldXY) {Origin = pt0};
Vector3d direction = new Vector3d(helperPlane.XAxis);
direction.Rotate(RhinoMath.ToRadians(rotationAngle), helperPlane.ZAxis);

Line line = new Line(pt0, direction, 2.0);
1 Like

Dude you saved my day. Thanks alot.

Regards,
Wil