Sign in to follow this  

Point Reflection

This topic is 4170 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

I would like to reflect a point across a line in 2D space. The point I would like to reflect is (x, y) and I know two points on the line (a, b)-(c, d). What would the formula be to find the new x and y coordinates of the reflected point?

Share this post


Link to post
Share on other sites
By analogy with 3D:

A line in 2D (like a plane in 3D) can be thought of as all points r such that r.n = d, where n is a unit normal to the line and d is a scalar constant.

To reflect a point across it, first find the value r.n for the point; call this c. The distance from the line is c-d, and to reflect the point you need to add 2(d-c)n to it.

To find n and d from two points:
- n = (x2 - x1, y2 - y1) normalised, and
- d = (either point).n.

Share this post


Link to post
Share on other sites
Sorry, I don't understand this that much, I'm just a novice. I'm not looking for anything in C++ though. I just want a general equation in terms of the variables mentioned above. This is because it needs to be translated into different language(s). Even if someone could give me the equation to find the point where the normal intersects the line I could take it from there. Thanks.

Share this post


Link to post
Share on other sites
Ok... we start with the line connecting the points (a,b) and (c,d), and an arbitrary point (u,v) that you wish to reflect in this line {I'm using u and v for the coordinates because I like to use x and y for variables}.

First we want an equation for the line connecting (a,b) and (c,d); call this f(x). Since f(x) is a straight line, it takes the form f(x) = mx + k. The gradient m is easily calculated as dy/dx = (b-d)/(a-c).

Now since f(a) = b, we see that
a*(b-d)/(a-c) + k = b,
and hence k = b - a*(b-d)/(a-c).

Next we need to find a line perpendicular to f(x), call this g(x). Again, since this is a straight line we can say g(x) = Mx + K, and furthermore since this is perpendicular to f(x) we know that:
mM = -1,
and hence M = (c-a)/(b-d).

We find K just the same as before, i.e. by using f(u) = v. You should find that:
K = v - u*(c-a)/(b-d).

The penultimate step is to find the single point where these two lines intersect. Again this is easily done as f(x) = g(x) implies that:
mx + k = Mx + K,
and thus x = (K - k)/(m - M) {we could also calculate the value of y at this point, but it is not needed yet}.

Finally we find the horizontal distance between the original point (u,v) and the point f and g intersect. Simply use:
d = |(K - k)/(m - M) - u|.
Now our reflected point (u',v') is at a horizontal distance of 2d away from (u,v), and thus:
u' = u + 2d {here you may have to use u - 2d depending on directions and what not}. Then to calculate v' just remember g(u') = v'.

Hope this helps; I think it's right but haven't had time to check my working ;)

Share this post


Link to post
Share on other sites
Okay, thanks. I have the program mostly written down. All of this makes sense to me except for the last part. Exactly how do I calculate v' ? I am also using computer coordinates so do I have to use u' = u + 2d or u' = u - 2d ? Thanks for your patience.

EDIT: Also, to calculate the location of the reflected point would I use u' = u' + (u' - u) and v' = v' + (v' - v) ?

Share this post


Link to post
Share on other sites
Quote:
Original post by erifash
Okay, thanks. I have the program mostly written down. All of this makes sense to me except for the last part. Exactly how do I calculate v' ? I am also using computer coordinates so do I have to use u' = u + 2d or u' = u - 2d ? Thanks for your patience.

EDIT: Also, to calculate the location of the reflected point would I use u' = u' + (u' - u) and v' = v' + (v' - v) ?


Actually if you ignore the absolute value for d then u' = u + 2d should work regardless of direction - I think. For v' remember you the formula for g(x) (the line containing (u,v) and (u',v') that is perpendicular to f), and this formula gives y when given x, so you can use:

v' = Mu' + K

Share this post


Link to post
Share on other sites

This topic is 4170 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this