How to get Normal vector of a Line?

How to get Normal vector of a Line?

nur91m
Advocate Advocate
4,417 Views
6 Replies
Message 1 of 7

How to get Normal vector of a Line?

nur91m
Advocate
Advocate

Hi all. When I try to get the normal vector of a line I get (0,0,1) vector though I tried any rotation with my line. How should I get the normal vector of a line?

 

Line line = new Line(pt1,pt2);
Vector3d v3d = line.Normal;
ed.WriteMessage(line.Normal.ToString());

 

0 Likes
4,418 Views
6 Replies
Replies (6)
Message 2 of 7

ActivistInvestor
Mentor
Mentor

Lines drawn while the UCS is set to WORLD have no normal vector.

 

So, the Normal property returns the 'default' normal vector, which is the WCS Z axis.

 

If you draw a line in a non-world UCS, it will have an explicit normal vector and Normal returns that.

Message 3 of 7

nur91m
Advocate
Advocate

Thanks for information. I will just calculate normal with formula Smiley Tongue

0 Likes
Message 4 of 7

_gile
Consultant
Consultant

nur91m a écrit :

Thanks for information. I will just calculate normal with formula Smiley Tongue


Geometrically, you can not calculate the normal of a line because it does not define a plane (a line belongs to an infinity of planes).

As @ActivistInvestor said, AutoCAD defines the "extrusion direction" of a line (Normal property or DXF code 210) with the Z axis of the coordinate system that was active when the line was drawn.
But a line can be drawn not parallel to the current XY plane.
This data is therefore not reliably linked to the geometry of the line.

For example, in the WCS, you can draw a line from (10, 10, 0) to (10, 10, 20).
The direction of extrusion of the line * would be identical to the axis WCS Z (0 0 1) despite the fact that this line is parallel to this direction.

* You can get it by evaluating the expression LISP: (cdr (assoc 210 (entget (entlast))) after drawing the line.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 7

_gile
Consultant
Consultant

Perhaps I misundertood the request.

If you want the unit vector (normalized) of the line direction, simply do:

line.StartPoint.GetVectorTo(line.Endpoint).GetNormal();

or

(line.EndPoint - line.StartPoint).GetNormal();

If I'm still wrong, please clarify what you're trying to get.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 6 of 7

ActivistInvestor
Mentor
Mentor

Just to clarify, as @_gile mentioned, a line has no normal. The Normal property returns a value that is used by AutoCAD to extrude the line if you give it a thickness.

 

If the line was drawn in the XY plane of the current UCS (and wasn't edited afterwards), the value returned by Normal will be the Z-axis of the UCS that was current when the line was drawn. But, you can't rely on that vector to be perpendicular to the line, because it may not be.

0 Likes
Message 7 of 7

_gile
Consultant
Consultant

Activist_Investor a écrit :

Just to clarify, as @_gile mentioned, a line has no normal. The Normal property returns a value that is used by AutoCAD to extrude the line if you give it a thickness.

 

If the line was drawn in the XY plane of the current UCS (and wasn't edited afterwards), the value returned by Normal will be the Z-axis of the UCS that was current when the line was drawn. But, you can't rely on that vector to be perpendicular to the line, because it may not be.


Thanks for clarifying this in good English.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes