The coordinates for my Javascript game are angle based when I use Sin Cos and Tan?

JavaScript coordinates of Sin, Cos or Tan? I am trying to learn some basic trigonometry for developing games in a web browser. I know the rule of soh cah toa, etc. I know that we also work between -1 and 1.

I'm confused, although I need to parse the x and y coordinates separately depending on the angle.

Here is what I need to work out the direction of my angle in x and y, which works (thanks Loktar).

velY = -Math.cos(angle * Math.PI / 180) * thrust;
velX = Math.sin(angle * Math.PI / 180) * thrust;

What I understand from this, I find cos x and y based on a small formula to convert my variable angle to radians.

But why do we need to use cos for x and sin for y? Where is the tan? Is it connected with 4 quadrants of a circle?

How do I know when to use sin cos or tan, when they give me only an angle, and I need to find out where on the circle, where the angles are, using x, y?

Any simple diagrams or explanations will be extremely helpful!

thank

+3
source share
1 answer

Basic definitions (from your book of trigonometry):

cos ϴ = x/h, sin ϴ = y/h

ASCII royalty-free art to describe x, y, and H:

         _
         /\  assume we're going this way 
        /
       /|
      / |
  h  /  |
    /   |  Y
   /    |
  /ϴ    |
 +-------
    X

A vector can be divided into the sum of two vectors. (you can think about it in the diagram, since the transition to the northeast for H meters is the same as east for X meters and north for Y meters)

H in this case matches your current thrust. You want to find components X and Y of this target.

since cos Θ = X / H (the basic definition of cosine), we can say (through simple algebra)

X = H * cos ϴ

, Θ . , Math.PI/180, . ,

ϴ = angle * Math.PI / 180

! ( )

cos (angle * Math.PI / 180) = X / H

H - , X - .

" ", - . " ? ". . - --------> . , " ", .. 0 12:00. , , X Y . , - X Y .

standard 'math' coordinate system
            _
             /\  
            /
           /|
          / |       angles increase counterclockwise
      h  /  |
        /   |  Y
       /    |
      /ϴ    |
     +----------- (zero degrees starts here)
  (0,0)  X       


your coordinate system

  (zero degrees starts here)
       ^
       |   angles increase clockwise
       |   /
       |  /
       |ϴ/
       |/
       +

, ? ,

 ^ y-axis
 |
 |
 +----> x-axis

, (, )

+------> x-axis
|
|
v y-axis

y , y 1,

+12

Source: https://habr.com/ru/post/1792765/


All Articles