1
\$\begingroup\$

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

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

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;
\$\endgroup\$
  • \$\begingroup\$ It's working, but you didn't use the result from you got from c and d \$\endgroup\$ – TenOutOfTen Jun 13 '18 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\$ – HolyBlackCat Jun 13 '18 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\$ – TenOutOfTen Jun 13 '18 at 15:26
  • \$\begingroup\$ @TenOutOfTen It's simply 2*center - point. \$\endgroup\$ – HolyBlackCat Jun 13 '18 at 15:29

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.