Skip to content

Instantly share code, notes, and snippets.

@vladanyes
Last active July 12, 2019 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladanyes/f589f1fbd25e78a02f734f812ef50d74 to your computer and use it in GitHub Desktop.
Save vladanyes/f589f1fbd25e78a02f734f812ef50d74 to your computer and use it in GitHub Desktop.
Draw a line between two points(-180/+180)
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