We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Everyone uses midpoint formula, but we can use a different strategy instead:
Notice that to rotate (x, y) around the origin we can use (-x,-y).
Now all we have to do is move to the origin, perform reflection, and move back.
Lets employ an algorithm using the coordinates (px, py) and (qx, qy):
1. We move (px,py) and (qx,qy) such that (qx,qy) is at the origin and their distance is maintained. This gives the new coordinates of (px,py) to be (px-qx,py-qy)
2. Now use the rule and multiply by -1, to get (-1 * (px-qx), -1*(py-qy))
3. Now we go back to the original coordinate by adding back, to get (px + -1 (px-qx), py + -1(py-qy))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Find the Point
You are viewing a single comment's thread. Return to all comments →
Everyone uses midpoint formula, but we can use a different strategy instead:
Notice that to rotate (x, y) around the origin we can use (-x,-y). Now all we have to do is move to the origin, perform reflection, and move back.
Lets employ an algorithm using the coordinates (px, py) and (qx, qy): 1. We move (px,py) and (qx,qy) such that (qx,qy) is at the origin and their distance is maintained. This gives the new coordinates of (px,py) to be (px-qx,py-qy) 2. Now use the rule and multiply by -1, to get (-1 * (px-qx), -1*(py-qy)) 3. Now we go back to the original coordinate by adding back, to get (px + -1 (px-qx), py + -1(py-qy))