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.

enter image description here

  • \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Commented Jun 13, 2018 at 13:48
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Jun 13, 2018 at 14:57
  • \$\begingroup\$ @DMGregory please would you take a look at this for me if you can gamedev.stackexchange.com/questions/160161/… \$\endgroup\$ Commented Jun 27, 2018 at 14:54
  • \$\begingroup\$ @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 \$\endgroup\$ Commented Jun 29, 2018 at 20:17
  • \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Commented Jun 29, 2018 at 20:30

1 Answer 1


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;
  • \$\begingroup\$ It's working, but you didn't use the result from you got from c and d \$\endgroup\$ Commented Jun 13, 2018 at 14:59
  • \$\begingroup\$ @TenOutOfTen You asked for positions of points C and D yourself. :P "How can I find positions C and D and the reflection (Er)". \$\endgroup\$ Commented Jun 13, 2018 at 15:02
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Jun 13, 2018 at 15:26
  • \$\begingroup\$ @TenOutOfTen It's simply 2*center - point. \$\endgroup\$ Commented Jun 13, 2018 at 15:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .