0 votes

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.

in Engine by (2,462 points)
edited by

2 Answers

0 votes

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).

by (241 points)

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

0 votes

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.

by (241 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.