# Python - Getting the normal of a line

Hi,

I’m trying to create some Curves (lines) by offsetting existing ones.

I see that in the Curve class there is a method for creating an Offset one: Curve.CreateOffset Method.

To do this, you need to specify the original curve, the offset distance and the normal.

The API help states that the normal is ‘The normal of the plane defining the offset direction.’

I assume that the normal is something which I’ll need to extract from the original line, but I cannot see any Property in the Line or Curve class which hold the Normal.

Or maybe I need to create the normal from the original lines start and end points?

Thanks.

Keep in mind that lines are 1D objects. That means that they can lie on many planes and thus it’s impossible to define their normal. Arcs and circles on the other hand do have a normal because they can lie only in a single plane.

In the context of the API, the normal refers to a direction vector. The equivalent in dynamo is the translate node.That vector can be anywhere in the euclidean space and we only care about its direction.

I see, so if I need to specify ‘The normal of the plane defining the offset direction.’ as required for the Offset then it can only come from the Start and End points I guess?

The API help states that its looking for Autodesk.Revit.DB.XYZ for the normal - an XYZ is just a point isn’t it? and not a direction vector?

XYZs are both points and vectors Think of them as a vector that starts at the origin and ends at the XYZ coordinates.Have you seen the primer? It has a lot of examples on this:

http://dynamoprimer.com/05_Geometry-for-Computational-Design/5-2_vectors.html

1 Like

mmm, OK. Still struggling to understand this.

Surely a XYZ is a point not a vector, a vector requires a direction?

From Primer: There is a key difference though: Points describe a position in a given coordinate system while Vectors describe a relative difference in position which is the same as saying “direction.”

But your saying that Revit work out a vector from the origin to the XYZ coordinates that I’ll specify? I don’t see how this would relate to my line though?

I assume this is required to work out what side to Offset the line to… Maybe I’m miss understanding why a vector is required for the Offset?

Kevin,

The reason they want a Vector for this case is because a Vector has Direction and Magnitude (Length) which in this case would be the direction in which you want to offset the curve in, and by how much you want to offset it. The reason one can express (represent) a vector as a XYZ coordinate is because typically in Cartesian coordinates vectors are considered to be always originated at 0,0,0 so the Direction/Magnitude can be calculted from 0,0,0 to X,Y,Z that you defined. The easiest way to imagine a Vector is by two points. Origin and Target and represent it with a Line. That’s how I always think of them. Hope this helps.

1 Like

Will attempt to explain with an analogy …

Say you want to offset a line by a distance R

Now, Imagine the line to be the axis of a cylinder (of radius R)
All lines parallel to the axis drawn on the surface of the cylinder, have effectively been offset by R
This could me any number of lines.(a minimum of 360 assuming 1 line per degree)
So, you aren’t being specific enough by just specifying the offset distance. You’ll need to specify the direction.

The base profile of the cylinder is a circle, the center of which is the start/end point of the axis.
Imagine the vector / direction / normal to be a line joining the center point to the start/end point of the desired line drawn on the surface.

1 Like

@Kevin_Bell

2 Likes

Ok, so I understand that the normal is effectively defines the plane for the offset based on the origin (I think I was getting confused with the fact that I’m working with a detail line which I assumed was 2D).

I put together this as a sample example to try to understand the use of the normal in an offset:

With the script being:

Offset Room Boundary.dyn (44.8 KB)

This offsets the line based on the sliders, I get that whilst its a detail line, its still offsetting in 3D space based on the normal plane, as per the graphic in Dimitar’s post above.

But if I wanted to offset the original line by, say, 100" to the left would it not be a case of setting:

Distance to 100
X Normal to 0
Y Normal to 0
Z Normal to any value.
?

But that doesn’t work.

I think the problem is that I cannot work out the ‘left’ or ‘right’ side of the line if the Normal is based on a vector between the origin and the point I specify?

OK, I think I’ve worked out whats been confusing me.

A normal of X=0. Y=0, Z=1 will produce an offset as expected, it was the distance that didn’t seem to work out.

The reason is that I’ve forgotten that Revit internally works in feet, (I work in Metres) so, if I convert then it offsets as expected…