• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Directions (Angles,Cos,Sin...) How does it work in wc3?

Status
Not open for further replies.
Level 3
Joined
Oct 10, 2017
Messages
32
I'll be honest, I'm not a genius when it comes to math. Currently I'm really struggling with angles and such in vJass. I don't know how to calculate the locations for my spell. For example, I want to make a fireball, that spawns at the casters position and moves to the target location and deals dmg on its way and at the end.

How would I actually start doing this? I've tried looking at other peoples code, even tho it is very difficult, to understand what other people write at my current level. Specially when they don't format properly.

The tutorials here and elsewhere only cover basic stuff and when I ask in Discord, they tell me its basic math x) which I don't understand to begin with. It would be nice if there was some kind of guide (or a person) that could help me understand that better. I will most likely need that kind of stuff for many different things in my map.

Specially the different math functions that are relevant to calculate the different locations

i.e

bj_DETOGRAD
bj_RADTODEG

and just in general when do you use these, why do you use these and what I asked for above. I hope someone can help me with this.

In the picture you will see a piece of code from someone else, to perhaps better understand what I'm talking about.
 

Attachments

  • Capture.PNG
    Capture.PNG
    30 KB · Views: 57
Level 9
Joined
Mar 26, 2017
Messages
376
To use Sinus and Cosinus, you first need to know the angle between the source and the target. You obtain this by putting the source and target coordinates into a function.

In JASS you can do this with following function:
Code:
Atan2(ty-y,tx-x))
x and y mean source coordinates, tx and ty the target coordinates.

This function results in radians. What radians actually mean: you can visualize it as the degrees of the angle divided by 57.3.
But you don't need to care about degrees, for sinus and cosinus you need radians. Lets call the radians value that we just obtained: r.

Now when you want to move an object 100 units in the desired direction you do this:
new X coordinate = current X coordinate + Cos(r)*100
new Y coordinate = current Y coordinate + Sin(r)*100
 
Level 24
Joined
Jun 26, 2020
Messages
1,852
Ok, I will try to explain everything in the most simple way.
First, there are different types of angular measurement units, some of them are degrees and radians, degrees is by dividing a complete turn in 360 pieces, but I think you know it, radians is the same but instead of 360 is 2*PI, explain the reason of this requires advance math, but using radians is the most easy way to calculate the trigonometric identities so bj_DETOGRAD is to convert a degree angle to a radian and bj_RADTODEG is the same but the opposite.

Next step imagine you have a right triangle
upload_2021-1-20_18-40-9.png

You have the angle A and the ratio of the values of a and c is called "sine of A" the meaning of sine is "opposite side over hipotenuse" (I think you know what I mean) and the ratio of the values of b and c is called "cosine of A" the meaning of cosine is "adjacent side over hipotenuse", and the ratio of the values of a and b is called "tangent of A" and tangent is "opposite side over adjacent side".
The inverse function of tangent is arctangent, so if you have the value of a/b and you wanna know from what angle is tangent you use Atan(a/b)=A.

Next step imagine we are in a cartesian plane (the game map is a cartesian plane)
pendiente-de-una-recta.gif

Imagine P1 is the point of the caster with coords (x1,y1) and P2 is the point of the target with coords (x2,y2), if you wanna know the value of the point P2 reffering to the point P1 follow this steps:
  • You see there is a right triangle, to calculate the value of the angle you can calculate the arctangent of the values of the sides whose values are "y2-y1" and "x2-x1" so the angle is Atan((y2-y1)/(x2-x1).
  • Now to move the unit step by step from point P1 to P2 we call direction the angle, if you move the unit 30 units in a direction called "a" you create a new right triangle like the previous
  • upload_2021-1-20_19-3-12.png
  • So to move a unit from point P1(x,y) to point P you have to set the new coords of the unit to (x+dx,y+dy) but what are the values of dx and dy?, if you remember the meanings of sine and cosine you know that Sin(a)=dy/30 and Cos(a)=dx/30, so the values are dx=30*Cos(a) and dy=30*Sin(a) so you have to set the coords of the unit to (x+30*Cos(a),y+30*Sin(a))
I hope you understand what I explain.
 
Last edited:
Status
Not open for further replies.
Top