I have the following code
var xPos = 0, yPos = 0, angle = 45, distance = 1; var yDelta = Math.sin(angle) * distance, xDelta = Math.sqrt((distance * distance) -(yDelta * yDelta)); yPos += yDelta; xPos += xDelta;
- Starting at coordinate (0,0)
- Move 1 step at 45 degrees
- To get the new coordinates I need to get the distance moved up
- As sin(theta) = opposite/hypotenuse this should be sin(theta) * hypotenuse
- And the distance moved across
- As this is a right angled triangle this should mean hypotenuse squared - opposite (that we calculated in the previous step) squared.
This gives me (0.5253, 0.8509), but this calculator tells me that it should be 0.7071 for each side. Can anyone explain what's wrong with my reasoning?