Lines
Geometric definition
In this context, a line refers to straight segments going from a point “A” to a point “B”. This implies several differences with the “Point” objects we have just seen before: lines have a length, a beginning and an end, and thus a direction.
How to add
RhinoCommons
import Rhino.Geometry as rg
import scriptcontext as sc
# Parameters to create the line
point_A = rg.Point3d(0, 0, 0)
point_B = rg.Point3d(1, 1, 1)
# Will create a line from point_A to point_B
my_line = rg.Line(point_A, point_B)
sc.doc.Objects.AddLine(my_line)
RhinoScriptSyntax
import rhinoscriptsyntax as rs
# Parameters to create the line
point_A = rs.AddPoint((0, 0, 0))
point_B = rs.AddPoint((1, 1, 1))
# Will create and add to the workspace a line from point_A to point_B
rs.AddLine(point_A, point_B)
Main methods and properties
Methods
Among the main method we have:
# Will extend the line by 1 at the beginning, and 2 at the end:
my_line.Extend(1,2)
# Will flip the line, switching the beginning and the end
my_line.Flip()
Properties
Among the main properties, we have:
# Will retrieve the direction vector of the line
direction_vector = my_line.Direction
# Will retrieve the start point of the line
start_point = my_line.From
# Will retrieve the end point of the line
end_point = my_line.To
🛠 Exercise
01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍
Solutions:
01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍