• Advertisement


This topic is now archived and is closed to further replies.

Reflect 2D vector from a line

This topic is 5079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Having a vector a, and a line (or other vector), there is a direct method to reflect the vector a from the line axis ? I know that can make this by movin line to origin, rotating line to align it to an coord axis Y and reflecting by Y, and later do the steps backwards.

Share this post

Link to post
Share on other sites
rewrite your vector a as a sum of two vectors a = ap + ao.

ap is parallel to the 2nd vector b (line) : ap = x*b. You´ll most probably (=best) have to use the dot product a*b to find x.

ao is orthogonal to b. Best obtained by ao = a - ap.

For the reflected vector a'': a'' = ap - ao.
In words: The parallel part of a remains unchanged (that´s what´ll happen if you "reflect" your line on itself, no?) while the orthogonal part changes it´s direction.

Sadly, you didn´t explicitely say how you´d "reflect" ("to mirror" might fit in better) your vector on the Y-Axis but above is most probably what you meant.

btw.: If you want to "reflect" a vector on a line that doesn´t pass through the origin, then I don´t even know what you want to do (mirroring a point, perhaps?).

Share this post

Link to post
Share on other sites
I thing I may have missunderstood your question:

Vector2D Reflection(Vector2D vec, Vector2D lp1, Vector2D lp2)
Vector2D normal;
normal.x = lp2.x-lp1.x;
normal.y = lp2.y-lp1.y;
float temp = normal.x;
normal.x = -normal.y;
normal.y = temp;

float dot2 = 2 * vec.Dot(normal);

return vec;

That may or may not help depending on what you are looking for...

Share this post

Link to post
Share on other sites

  • Advertisement