Js math atan2 cos sin

Source: Internet
Author: User

Js math atan2 cos sin

1. Give the relative coordinate center o, p1 to o distance l, p1 to X axis angle (0 ~ 2PI)

left:x0+Math.cos(angle)top:  y0+Math.sin(angle)

2. The relative coordinate center o and p1 coordinates are given, and the angle between the X axis of p1 is obtained.

// Angle greater than-Math. PI, less than Math. PI // (-linear, linear) var angle = astan2 (y1-y0, x1-x0 );
Case:

Vczly + bXxbDatq + 4 + tfF16q2r6GjPC9zdHJvbmc + PC9wPg0KPHByZSBjbGFzcz0 = "brush: java;">/* Knowledge point: the angle from which the axis is switched is equal to the angle from which the cube is rotated. Obtain angle x, y */var canvas, contxt, canvas = document. getElementById ('mycanvas '); contxt = canvas. getContext (2d); var drawWall = function () {contxt. save (); contxt. strokeStyle = #000; contxt. lineWidth = 5; contxt. beginPath (); contxt. moveTo (100,0); contxt. lineTo () contxt. stroke (); contxt. closePath (); contxt. restore () ;}; var drawLine = function (x, y) {contxt. save (); contxt. strokeStyle = #000; contxt. lineWidth = 2; contxt. beginPath (); contxt. moveTo (); contxt. lineTo (300 + x, y) contxt. stroke (); contxt. closePath (); contxt. restore () ;}; var drawRect = function (x, y, angle) {contxt. save (); contxt. fillStyle = # f00; contxt. translate (300 + x, y); contxt. rotate (angle + Math. PI/2); contxt. rect (-100,-50,200,100); contxt. fill (); contxt. restore () ;}; var angle, increase, width, height, x, y, radius; angle = Math. PI/3; increase = Math. PI/3/200; width = 200; height = 100; radius = 300; var onframe = function () {contxt. clearRect (0,0, 800,600); drawWall (); x = radius * Math. cos (angle); y = radius * Math. sin (angle); drawLine (x, y); drawRect (x, y, angle); if (angle> (Math. PI/3*2) {increase =-increase;} else if (angle

 

Related Article

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.