IAbstract
IAbstract

Reputation: 19881

Why is 45 degree line off?

I am drawing 2 lines:

  1. x:10, y:10; angle: 45 deg; length: 100
  2. x:25, y:10; angle: 45 deg; length: 100

Here is the image from the two lines:
enter image description here

The upper left is, of course (0,0). The line on the left appears to be drawn correctly. What is happening on the sencond line?

Here is my formula for converting the degrees and length to end points:

    var radians:Number = angle * Math.PI / 180;

    _x2 = Math.cos(radians) * length;
    _y2 = Math.sin(radians) * length;

Upvotes: 1

Views: 64

Answers (1)

Peter B
Peter B

Reputation: 24280

Both lines are wrong, the formulas for both endpoints should be:

_x2 = x + Math.cos(radians) * length;
_y2 = y + Math.sin(radians) * length;

Upvotes: 4

Related Questions