Last active
July 12, 2019 14:30
-
-
Save vladanyes/f589f1fbd25e78a02f734f812ef50d74 to your computer and use it in GitHub Desktop.
Draw a line between two points(-180/+180)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
normalizeAngle = angle => { | |
let newAngle = angle; | |
if (newAngle <= -180) newAngle += 360; | |
if (newAngle > 180) newAngle -= 360; | |
return newAngle; | |
}; | |
calculateAngle = point => { | |
return (Math.atan2(point.y - INITIAL_POINT.y, point.x - INITIAL_POINT.x) * 180 / Math.PI) + 90; | |
}; | |
calculateCoordinates = angle => { | |
if (!angle) return { x: 0, y: 0 }; | |
const length = VECTOR_LEGHT; | |
const angleInRadians = (angle - 90) * Math.PI / 180; | |
return { | |
x: length * Math.cos(angleInRadians) + INITIAL_POINT.x, | |
y: length * Math.sin(angleInRadians) + INITIAL_POINT.y, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment