defendPos = { "x" : 41 , "y" : 40 }
defendPos . x += 10 * Math.cos (angle)
defendPos . y += 10 * Math.sin (angle)
What does the three lines of code represent. I want like a translation in some sort of way
defendPos = { "x" : 41 , "y" : 40 }
defendPos . x += 10 * Math.cos (angle)
defendPos . y += 10 * Math.sin (angle)
What does the three lines of code represent. I want like a translation in some sort of way
Il me semble que cāest pour donner un certain type dāangle. Jāai plus ou mois Ć©tudier la chose sur un autre site de programmation de jeu. Et au lieu de donner un chiffre en dur, on lui attribut le math.cos en x. et le math.sin en y. Cāest tous simplement de la trigonomĆ©trie, on apprend cela en gĆ©ometrie. Cela te permet de calculer un angle.
Jāespere que cela va tāaider.
Hi Yeet,
The sin (short for sine) and cos (short for cosine) of an angle describes the ratio between the lengths of the different sides of a triangle. So if you know one of the angles in a (right angle) triangle, and one of the side lengths, you can use the ratios to work out the lengths of the other two sides. This is a really useful thing to be able to do in real life - from working out the height of a tree, to calculating the path a rocket will take on launch! Itās called trigonometry.
For more information about trig, look at a page like this (or Google has plenty of others).
The three lines of code you give will work out the x and y of the position that youāll get to if you move 10 units in the direction āangleā from your start position. The function with cos gives how far along the x axis you need to go, and the function with sin gives how far along the y axis. Pretty cool (I think at least).
Jenny
These should get you hooked up for the Trig levels:
Sine(theta)=Opposite/Hypotenuse
Cosine(theta)=Adjacent/Hypotenuse
Tangent(theta)=Opposite/Adjacent
Law of sines: a/sin(a)=b/sin(b)=c/sin(c)
.
Law of cosines: c^2=a^2+b^2-2ab*cos(c)
Thereās more, but from what I remember these are the ones youāll use most.
If Iām not mistaken this part of code is from the level with defending Hushbaum?
These three lines help you to form a circle around (41,40) .
You can go to
https://codecombat.com/play/level/forest-flower-grove?
and try to use function that draw a circle to change numbers and look what happens)
wait how does the sin and cosine help find the distance of a circle or square?
wait how does the sin and cosine help find the distance of a circle or square???
Hi @Yeet, please could you not repeat your post twice, it wonāt get you help any faster.
Danny
Look up āUnit Circleā on the web and itāll tell you how to utilize Trigonometric functions for circular formations.