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.
Information we have: a point P1(x1, y1) and an origin O(xo, yo).
What we want to know, P2(x2,y2).
Visualization that worked for me(think of singular lines):
x-axis |-----------x1—----------xo—------x2—----|
Formula for midpoint xo is: xo = (x2 + x1)/ 2
We have xo, so rearrange to solve for x2:
New formula: x2 = 2xo - x1
Why the formula for point-reflection works:
When subtracting a coordinate and changing the sign, the coordinate rotates 180 degrees.
Example: given x1 = 2, assuming origin is O(0,0), the opposite of x1 would be -2, so
x2 = 2(0) - 2
|--------- -2 —---------------Ox = 0 —--------------- 2 —---|
Take note of the information that you have and rearrange/find a formula to help solve the problem.
Break down the diagram into something simpler.
For shapes it would be the same concept, just apply to each point.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Find the Point
You are viewing a single comment's thread. Return to all comments →
A way to think about solving the problem
Information we have: a point P1(x1, y1) and an origin O(xo, yo). What we want to know, P2(x2,y2). Visualization that worked for me(think of singular lines): x-axis |-----------x1—----------xo—------x2—----| Formula for midpoint xo is: xo = (x2 + x1)/ 2 We have xo, so rearrange to solve for x2: New formula: x2 = 2xo - x1
Why the formula for point-reflection works: When subtracting a coordinate and changing the sign, the coordinate rotates 180 degrees. Example: given x1 = 2, assuming origin is O(0,0), the opposite of x1 would be -2, so x2 = 2(0) - 2
|--------- -2 —---------------Ox = 0 —--------------- 2 —---|
Take note of the information that you have and rearrange/find a formula to help solve the problem. Break down the diagram into something simpler.
For shapes it would be the same concept, just apply to each point.