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
lvec.Rotate(Rhino.RhinoMath.ToRadians(ang),Rhino.Geometry.Vector3d.ZAxis)
line=Rhino.Geometry.Line(spt,lvec,length)
sc.doc.Objects.AddLine(line)
sc.doc.Views.Redraw()
MakeAngledLine()
One of those should work for me. Thanks.
and one more just to make sure you did not miss itâŚ
-_Line 0 10 <60
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
return Rhino.Geometry.Point3d(adjacent, opposite, point.Z)
p0 = Rhino.Geometry.Point3d(0.0, 0.0, 0.0)
angle = Rhino.RhinoMath.ToRadians(27.6)
distance = 15.4
p1 = PointFromAngleDistance(p0, angle, distance)
line = Rhino.Geometry.Line(p0, p1)
sc.doc.Objects.AddLine(line)
sc.doc.Views.Redraw()
â Dale
Thank you Dale!!