# How can I find the reflection of a point in a perpendicular line?

From the image below I know the positions A and B. How can I find positions C and D and the reflection (Er) of an object E in the line CD? I saw the solution in How can I reflect a point about a line in Unity? but I don't understand it enough to apply it in my case. Please note that I'm trying to achieve this in 2D.

• This looks like an exact duplicate of the question you link, which already contains copy-and-paste ready code you can use in Unity. If you can clarify what it is about the linked question's answer you don't understand or is not working for you, we can focus on that specific issue, or improve that answer. – DMGregory Jun 13 '18 at 13:48
• @DMGregory I guess it's the maths, I'm struggling to understand especially how the last line with Vector3.Dot. Maybe a diagram showing how works out would help. – TenOutOfTen Jun 13 '18 at 14:57
• @DMGregory please would you take a look at this for me if you can gamedev.stackexchange.com/questions/160161/… – TenOutOfTen Jun 27 '18 at 14:54
• @DMGregory I am still trying to solve the above linked question. Please could you look at it for me if you get any spare time – TenOutOfTen Jun 29 '18 at 20:17
• Please do not repeatedly tag users if they haven't replied to you. The nature of StackExchange is that anyone can suggest answers, edits, etc, so you don't need to count on a particular user's input. – DMGregory Jun 29 '18 at 20:30

I'm not familiar with unity, but here's an answer in GLSL-like pseudocode.

vec2 a = ..., b = ..., e = ...;
vec2 center = (a + b) / 2; // the intersection of the two lines
vec2 n = a - center; // mirror normal
vec2 c = center + vec2(n.y, -n.x); // here I assume that the length of the mirror is
vec2 d = center + vec2(-n.y, n.x); //   equal to the distance between A and B
n = normalize(n);
float l = dot(n, e - center); // distance between CD and E
vec2 er = e - 2*l*n;

• It's working, but you didn't use the result from you got from c and d – TenOutOfTen Jun 13 '18 at 14:59
• @TenOutOfTen You asked for positions of points C and D yourself. :P "How can I find positions C and D and the reflection (Er)". – HolyBlackCat Jun 13 '18 at 15:02
• Okay, that's true. :) I thought their results were necessary for finding Er. May I ask, how will the solution change for points getting inflected along a line as shown in imgur.com/a/CUpFbie? – TenOutOfTen Jun 13 '18 at 15:26
• @TenOutOfTen It's simply 2*center - point. – HolyBlackCat Jun 13 '18 at 15:29