Add line perpedincular to existing line - c#

Hi,

Probably an easy question regarding C#, but after a few hours I am still not able to do it.
I have a slanted line and i would like to add line perpendicular to the existing line.
Can you please give me some hints how this can be done?

You need two pieces of information:

  • The plane that the line and the perpendicular line should contain (for example the XY-plane)
  • the direction (positive/negative).

Then:

Line l; // your line
Plane xy = Plane.WorldXY; // my assumption: the line and the perpendicular line must be in the XYplane

double direction = 1.0; // can also be -1.0

Vector3d perp = Vector3d.CrossProduct(l.Direction, xy.Normal);
perp *= direction;

Line p = new Line(l.From, perp);

doc.Objects.AddLine(p); // I'm not sure about the exact syntax here

Thanks