[As functional code Tutorial 15] The distance formula between points

Source: Internet
Author: User

As says:

Math.sqrt (Math.pow (p1._x-p2._x), 2) +math.pow ((p1._y-p2._y), 2)

From this formula you can deduce the formula of distance from a point to the origin:

Because the origin coordinates are (0,0), the formula is deformed as follows

MATH.SQRT (p1._x * p1._x + p1._y * p1._y)

Here we'll use these two formulas to make some effects.

Instance one: Rotate the pointer

Ideas:

A number of theta methods for an angle are as follows:

sine function sinθ=y/r

cosine function cosθ=x/r

Tangent function tanθ=y/x

cotangent function cotθ=x/y

secant function secθ=r/x

Residual cut function cscθ=r/y

These trigonometric functions can be used to find the same angle θ.

In this instance, only Atan and ACOs are used instead of other trigonometric functions because their return value is an arbitrary number, while the return value of the other function is a qualified number.

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.