1
\$\begingroup\$

Pardon me if this sounds primitive. I have created a bezier curve with control points A, B, C, D, which are known (see image below). How can I find control points B1, C1, D1 for a new bezier curve reflected in AR1 and A2, B2 and C2 for a new bezier curve reflected in DR2?

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ Can AR1 be an arbitary line segment or only paralell to the y axis? \$\endgroup\$
    – Bálint
    Sep 24, 2018 at 5:49
  • \$\begingroup\$ @Bálint AR1 should be arbitrary, but as a reflection line the distance from D1 to R1 should be the same as R1 to D and so on. \$\endgroup\$ Sep 24, 2018 at 6:57
  • \$\begingroup\$ Still trying to get this solved \$\endgroup\$ Sep 25, 2018 at 15:43

1 Answer 1

2
\$\begingroup\$

Take the line going through AR1, the equation of this lines is

(x-A.x)(R1.y-A.y)=(y-A.y)(R1.x-A.x)
(R1.y-A.y)x - (R1.x-A.x)y = A.x(R1.y-A.y)-A.y(R1.x-A.x)

So the normal vector of this line is (R1.y-A.y, R1.x-A.x). This is the direction vector of the line perpendicular to it and since that goes through D, we can get the equation of that as well:

(R1.x-A.x)x-(R1.y-A.y)y=(R1.x-A.x)D.x-(R1.y-A.y)D.y

From this we isolate x for later use:

x = ((R1.x-A.x)D.x-((R1.y-A.y)(D.y+y))/(R1.x-A.x)
x = D.x - (R1.y-A.y)(D.y+y)/(R1.x-A.x)

Then we replace x in the other line's equation using this

(D.y+y)(R1.y-A.y)^2/(R1.x-A.x) - (R1.x-A.x)y = A.x(R1.y-A.y)-A.y(R1.x-A.x)

We then isolate y

y = (A.x(R1.y-A.y)-A.y(R1.x-A.x)-D.y*(R1.y-A.y)^2/(R1.x-A.x))/(R1.x-A.x+(R1.y-A.y)^2/(R1.x-A.x))

This is the only equation you actually need to implement.The right side should be given. After you find y, use it to calculate x using the

x = D.x - (R1.y-A.y)(D.y+y)/(R1.x-A.x)

equation

You should now have the coordinates of the closest point on the AR1 line to the D point (I suggest abstracting it and implementing a function, that given a line and a point does this, since you need to use it a couple of times). Now you just get the vector pointing from D to this new point, multiply it by 2 and add it to D to get D'. Repeat this process with C and B and you should have every control point.

\$\endgroup\$
11
  • 2
    \$\begingroup\$ I am trying to understand your answer. I don't know R1 and everything seems to be in terms of R1. I would be grateful if you would explicitly show how to calculate the points (or some of them) using C#, since I I used the Unity tag for the question. \$\endgroup\$ Sep 24, 2018 at 10:33
  • \$\begingroup\$ @coderificated Those are points, in unity You'd use vectors. If you do that, then you can almost just copy and paste it and they should work apart from the ^2 (which should be changed to a squareing) and how I didn't use * between some expressions \$\endgroup\$
    – Bálint
    Sep 24, 2018 at 10:40
  • \$\begingroup\$ To be honest with you, I'm really not sure how to arrive at D1 or the other points from your answer. You have provided the coordinates of the equation of a line AR1 but none of the points I asked in the question. \$\endgroup\$ Sep 24, 2018 at 11:36
  • \$\begingroup\$ @coderificated there's no D1, only D, and you should already have that since you used it to define the bezier curve \$\endgroup\$
    – Bálint
    Sep 24, 2018 at 12:13
  • \$\begingroup\$ From the question I posted I don't know B1, C1, D1, A2, B2 and C2 \$\endgroup\$ Sep 24, 2018 at 12:27

You must log in to answer this question.

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