# Create line by length and angle

Is there a way to create a line from a point of a defined length and angle?

Look in the Rhino help under ‘Accurate modeling’ [sic] or ‘Accurate drawing’.

I’m looking to do it with a script.

Do you mean a command macro, rhinoscript or python?

Yes. I would like to create the line in Rhino using a starting point, length and angle using Python.

I could write a function to do it but was looking for a command if it exists.

An angle between the line and what? In what plane is the angle measured? XY, XZ, YZ or an arbitrary plane?

This would make more sense if you use start point, a vector (direction) and length, like the standard Grasshopper Line SDL component. Otherwise your spec is too vague, angle alone is indeterminate.

XY plane, a starting point, a length and an angle.

I guess you mean the angle in the XY plane between the X direction and the line? It wasn’t easy but I’m glad that much is clarified…

Ok. I realize my question was too general. I guess what I am looking for are other ways to create a line without simply supplying predefined end points. For example when one is drawing in the top view and creating a series of lines you can specify the line length and then pick a direction on screen to place the line without knowing exactly where the end point should be. It places the line and maintains the length. So, using python code, I pick a start point (0,0,0 for example), define a length and specify an angle in relation to x. For example x+ would be 0 and the angles would 0 to 360 off of that. Or perhaps it has to be specified as a vector normal in relation to the XY plane.

I have already constructed a function to do this and maybe that’s the way it needs to be done. I was just probing for other ways to create lines other than specifying two end points.

A line is always determined by two points… In fact a RhinoCommon line object is exactly that.

If you look here, you can see the RhinoCommon methods available to construct a line:

https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Geometry_Line.htm

Ohterwise, you can always use trig to get the other endpoint of the line, or, just make a line along one axis and rotate it…

``````import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def MakeAngledLine():
spt=rs.GetPoint("Pick start point")
if not spt: return

length=rs.GetReal("Length?")
if length is None: return

ang=rs.GetReal("CCW Angle in degrees? (0=X Axis)")
if ang is None: return

lvec=Rhino.Geometry.Vector3d.XAxis
line=Rhino.Geometry.Line(spt,lvec,length)
sc.doc.Views.Redraw()
MakeAngledLine()
``````
2 Likes

One of those should work for me. Thanks.

and one more just to make sure you did not miss it…

-_Line 0 10 <60

1 Like

This is a command line entry I assume. I’ll try it. Thanks!!!

Yes, and the single “0” is a shortcut for 0,0,0 on the active CPlane. You can replace that with _Pause if you want to set the start point manually:
-_Line _Pause 10 <60

This does mostly what I am trying to do but it is just constraining the line to a 60 degree angle. I still need a point to finish the command.

You can “hardcode” that with a macro, but a proper script like Mitch posted, would be more comfortable if you want to alter the values.
-_Line _Pause r10,0,0 _SelNone _SelLast _Rotate r-10,0,0 60 _Enter

Hi @eric.bunn,

You can also use some trigonometry:

``````import System
import Rhino
import scriptcontext as sc

def PointFromAngleDistance(point, theta, hypotenuse):
adjacent = System.Math.Cos(theta) * hypotenuse + point.X
opposite = System.Math.Sin(theta) * hypotenuse + point.Y

p0 = Rhino.Geometry.Point3d(0.0, 0.0, 0.0)