gh.vectors

Points and Vectors in Grasshopper Scripting

There are many classes that could be used to store and manipulate points and vectors.


Point and vector operations:


Vector Addition:
Dim add_v As New On3dVector = v0 + v1

Vector Subtraction:
Dim subtract_vector As New On3dVector = v0 – v1

Vector between two points:
Dim dir_vector As New On3dVector = p1 – p0

Vector dot product:
(if result is positive number then vectors are in the same direction):
Dim dot_product As Double = v0 * v1

Vector cross product:
(result is a vector normal to the 2 input vectors)
Dim normal_v As New On3dVector = OnUtil.ON_CrossProduct( v0, v1 )

Scale a vector:
Dim scaled_v As New On3dVector = factor * v0

Move a point by a vector:
Dim moved_point As New On3dPoint = org_point + dir_vector

Distance between 2 points:
Dim distance As Double = pt0.DistanceTo(pt1)

Get unit vector:
(set vector length to 1)
v0.Unitize()

Get vector length:
Dim length As Double = v0.Length()

Categories

Configure Widgets