Vector 3D python explain

hello,

I need to understand how vector work in rhino, for example Ihave got 2 points, to create a vector with it’s simple. vector=rs.VectorCreate(pt1,pt2), but now i want to modifi the lenth of the vector, i’ve got a distnace, an d i want to change only the lenth of the vector, but i want to keep the direction, is it possible?

to finish, i need to to apply the vector to points, to move them… but I don’t know how… i Wrote this code:

import rhinoscriptsyntax as rs

olinept1,olinept2=rs.GetLine()


a=True
target=(olinept1,olinept2)
longueur=1
vector=rs.VectorCreate(olinept2,olinept1)
while a:
    vector=rs.VectorScale(vector,longueur)
    target=rs.MoveObject(target,vector)
    
    
    objects=rs.GetObjects('selectionne ce que tu veux aligner!!!!')
    if objects:
        pt1=rs.GetPoint('selectionne le point 1')
        pt2=rs.GetPoint('selectionne le point 2')
        reference=(pt1,pt2)
        longueur = rs.Distance(pt1,pt2)+1500
        for object in objects:
            rs.OrientObject(object,reference,target)
    
    
    else:
        a=False

but target is not a list of point…

@onlyforpeace - this might be useful.

– Dale

Yes, just multiply the unitized vector by the number you want, that changes its length. Or divide the length you want to have by the existing length.

Just add the vector to the point.

import rhinoscriptsyntax as rs

p1=rs.coerce3dpoint([0,0,0])
p2=rs.coerce3dpoint([1,1,0])
vec=rs.VectorCreate(p2,p1)
t_len=10.0

long_vec=rs.VectorUnitize(vec)*t_len

#or

long_vec=vec*(t_len/p1.DistanceTo(p2))

#or

vec=(p2-p1)
long_vec=vec*(t_len/p1.DistanceTo(p2))


rs.AddPoint(p1+(long_vec))
1 Like