Getting a Vector parallel to a line formed with nearby Vectors

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ertain

I have a line drawn by an array of Vector2s. What I would like to do is get a Vector2 parallel to a line which is drawn by nearbyVector2s. It would sort of look like this:

Moving a vector parallel

So it would be at a right angle to the line formed by P1 and P3. I’ve been using mixtures of the functions angle_to() and normalized() to try to get the position. But I can’t seem to get it.

Edit: As per kozaluss’ information, I’ll try to make things a bit clearer.

enter image description here

P1, P2, and P3 are the points of Vector2s. I’m trying to find the point of a vector (P4) that’s based upon the P2’s vector point such that it’s parallel to a line (the green line) which contains the points of the vectors P3 and P1.

:bust_in_silhouette: Reply From: kozaluss

I can not decipher what is a vector and what is a point on Your picture. But trying my best guess: If P1 and P3 are points in space (position vectors) then red vector (P3-P1) is a vector parallel to olive vector. But I do not know what are the blue lines about. Vectors do not carry their origin with themselves - they are always (0,0) based. Therefore to have a vector that is originated in point P2 you need two things - position and vector. Position would be P2 point, vector would be (P3-P1).

Thank you for the clarification on the origins of the vector. I’ll adjust my answer to this new information.

Ertain | 2018-09-06 14:48

:bust_in_silhouette: Reply From: kozaluss

So… Now I understand this like this:

var P1 = Vector2(...) # first point
var P3 = Vector2(...) # second point
var DirVector = P3-P1 # this gives us a vector parallel to green line
var NormDir = DirVector.Normalized() # we might want to normalize the direction for future operations
var P2 = Vector2(...) # third point - origin of the new parallel
var Multiplier = float(...) # some multiplier value to traverse the line
var PointOnParallelLine = P2 + NormDir * Multiplier # for Multiplier from -inf to +inf will give us all points on the parallel line including point P2 when Multiplier==0

So all You have to know now is what You want the Multiplier to be.

Thanks for the input, kozaluss. This approach should help me in my goal.

Ertain | 2018-09-08 06:39