#1 – Codewars 100 days challenge

#1 – Points of reflection (8 kyu)

Instructions:
“Point reflection” or “point symmetry” is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same dis…


This content originally appeared on DEV Community and was authored by Cesar Del rio

#1 - Points of reflection (8 kyu)

Instructions:
"Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction.

Task
Given two points P and Q, output the symmetric point of point P about Q. Each argument is a two-element array of integers representing the point's X and Y coordinates. Output should be in the same format, giving the X and Y coordinates of point P1. You do not have to validate the input.

My notes:

Image description

My solution:

function symmetricPoint(p, q) {
  return [2*q[0]-p[0], 2*q[1]-p[1] ]
}

Explanation
I found the formula for getting the P1 coordinate, the formula is P1(2Qx - Px, 2Qy - Py), then I just passed this formula with the array index positions and returned the result as an array

My Github
My twitter
Solve this Kata


This content originally appeared on DEV Community and was authored by Cesar Del rio


Print Share Comment Cite Upload Translate Updates
APA

Cesar Del rio | Sciencx (2021-12-30T21:18:59+00:00) #1 – Codewars 100 days challenge. Retrieved from https://www.scien.cx/2021/12/30/1-codewars-100-days-challenge/

MLA
" » #1 – Codewars 100 days challenge." Cesar Del rio | Sciencx - Thursday December 30, 2021, https://www.scien.cx/2021/12/30/1-codewars-100-days-challenge/
HARVARD
Cesar Del rio | Sciencx Thursday December 30, 2021 » #1 – Codewars 100 days challenge., viewed ,<https://www.scien.cx/2021/12/30/1-codewars-100-days-challenge/>
VANCOUVER
Cesar Del rio | Sciencx - » #1 – Codewars 100 days challenge. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/30/1-codewars-100-days-challenge/
CHICAGO
" » #1 – Codewars 100 days challenge." Cesar Del rio | Sciencx - Accessed . https://www.scien.cx/2021/12/30/1-codewars-100-days-challenge/
IEEE
" » #1 – Codewars 100 days challenge." Cesar Del rio | Sciencx [Online]. Available: https://www.scien.cx/2021/12/30/1-codewars-100-days-challenge/. [Accessed: ]
rf:citation
» #1 – Codewars 100 days challenge | Cesar Del rio | Sciencx | https://www.scien.cx/2021/12/30/1-codewars-100-days-challenge/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.