FLASN AS3 calculates the angle (radian, angle) between the line and the axis according to the two-point coordinate.

Source: Internet
Author: User

In development, it is sometimes necessary to compute the angle between a vector of two coordinate points and an axis, and then we use the results to rotate the component (rotation). The following shows the calculation method for the angle between the x axis and the y axis respectively.

1, the angle of the x axis


var p1:point = new Point (40,30);
var p2:point = new Point (80,60);

var angle:number = math.atan2 ((p2.y-p1.y), (p2.x-p1.x))//Radians 0.6435011087932844
var theta:number = angle* (180/MATH.PI); Angle 36.86989764584402

2, the angle of the Y axis

The calculation method is similar to the x-axis angle, except that the x and Y coordinate positions in the parameters are reversed when the radian is calculated.

var p1:point = new Point (40,30);
var p2:point = new Point (80,60);

var angle:number = math.atan2 ((p2.x-p1.x), (P2.Y-P1.Y))//Radians 0.9272952180016122
var theta:number = angle* (180/MATH.PI); Angle 53.13010235415598

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.