I want to translate a point to specific distance, along a line whose angle is given in degrees.
var initialPoint = [0,0]; //Starting Point
var distance = 100; //Distance in pixels to be translated
var degree = 45; //Direction of move
var translatedPoint = moveByDegree(initialPoint, degree, distance);
function moveByDegree(initialPoint, degree, distance)
{
//formula to generate translatedPoint by degree & distance
// . . .
return translatedPoint;
}
- 0 degree should move UP.
- 180 degree should move DOWN.
- 90 degree should move RIGHT.
- 270 degree should move LEFT.
- Other angles would correspond to a DIAGONAL direction.
Give me simple algorithm or JavaScript code.