Is there a way I can make, say, a cannon ball, have x/y velocities based on the cannon's direction? This isn't including gravity.
Offline
Sine, and cosine!
a topic on sine/cosine
Offline
More detail on how I could use it to help me, please?
Last edited by SeptimusHeap (2011-11-04 20:59:01)
Offline
Sine and cosine can specifically be used to determine a length based on an angle. I do believe that you can use this to find the best height and speed, and trajectory.
http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
http://scratch.mit.edu/projects/BATzerk/48863
Offline
Greatdane wrote:
Sine and cosine can specifically be used to determine a length based on an angle. I do believe that you can use this to find the best height and speed, and trajectory.
http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
http://scratch.mit.edu/projects/BATzerk/48863
I downloaded the project, but I don't see any trig blocks, just your general math blocks, + _ * and /.
Offline
wut. i don't understand what you just said. what is sine and cosine?
this is offtopic but i love your dynamite mod
Offline
resistance wrote:
wut. i don't understand what you just said. what is sine and cosine?
this is offtopic but i love your dynamite mod
Thanks.
It's trig, a type of advanced math that has to do with angles.
Offline
I've done this many times before. It's extremely useful. Try digging back into my projects, there's one called "Acceleration Test 2". That was my very first (working) attempt at what you're trying to achieve.
Last edited by LS97 (2011-11-05 08:57:19)
Offline
Ok, let me break it down. Sine is the ratio of a side to the hypotenuse (side not touching the right angle) of a right triangle, which is determined by the measure of the angle opposite to the side in question. So in a right triangle with angles 90, 45, 45, the ratio of a side to the hypotenuse is sin(45). Now when you fire a cannon, the force is distributed between the x and y velocities. Imagine it goes one unit forwards. Then you can drop a line perpendicular to the ground from the new position of the cannon ball. Now you have a right triangle: the line just drawn, the path traveled, and the distance between the cannon and the point where the new line met the ground. In fact, the sine of the angle of the cannon determines the Y velocity (ratio of the new line to the distance traveled, ie the percentage of force used in going UP). Similar logic works for X velocity.
Offline
Hardmath123 wrote:
Ok, let me break it down. Sine is the ratio of a side to the hypotenuse (side not touching the right angle) of a right triangle, which is determined by the measure of the angle opposite to the side in question. So in a right triangle with angles 90, 45, 45, the ratio of a side to the hypotenuse is sin(45). Now when you fire a cannon, the force is distributed between the x and y velocities. Imagine it goes one unit forwards. Then you can drop a line perpendicular to the ground from the new position of the cannon ball. Now you have a right triangle: the line just drawn, the path traveled, and the distance between the cannon and the point where the new line met the ground. In fact, the sine of the angle of the cannon determines the Y velocity (ratio of the new line to the distance traveled, ie the percentage of force used in going UP). Similar logic works for X velocity.
Umm...
We only spent 2 classes on trig last year, and that was over 6 months ago.
What I don't understand is the line just drawn thing that you said, and how I can implement this in code.
Offline
Ok... here's a code:
point in direction: 30
go to x: 0 y: 0
forever:
change y position by (sine of (direction))
change x position by (cos of (direction))
/forever
The sine of and cos of blocks can be found in the drop-down of the sqrt of () block. Hop it helps!
Offline
Hardmath123 wrote:
Ok... here's a code:
point in direction: 30
go to x: 0 y: 0
forever:
change y position by (sine of (direction))
change x position by (cos of (direction))
/forever
The sine of and cos of blocks can be found in the drop-down of the sqrt of () block. Hop it helps!![]()
Wouldn't x be sine? Because If a sprite is pointing in direction 90, it's sine is 1.0, so it would be going up, not right.
Offline
SeptimusHeap wrote:
Hardmath123 wrote:
Ok... here's a code:
point in direction: 30
go to x: 0 y: 0
forever:
change y position by (sine of (direction))
change x position by (cos of (direction))
/forever
The sine of and cos of blocks can be found in the drop-down of the sqrt of () block. Hop it helps!![]()
Wouldn't x be sine? Because If a sprite is pointing in direction 90, it's sine is 1.0, so it would be going up, not right.
Yes I believe X is sine.
Offline
LS97 wrote:
SeptimusHeap wrote:
Hardmath123 wrote:
Ok... here's a code:
point in direction: 30
go to x: 0 y: 0
forever:
change y position by (sine of (direction))
change x position by (cos of (direction))
/forever
The sine of and cos of blocks can be found in the drop-down of the sqrt of () block. Hop it helps!![]()
Wouldn't x be sine? Because If a sprite is pointing in direction 90, it's sine is 1.0, so it would be going up, not right.
Yes I believe X is sine.
Oh, yes, sorry, I forgot Scratch has a 90 degree rotated coordinate system (0 should be horizontal).
Offline
OK. 1 more thing, when I try 180 degrees, sine is like 1.2....
Why? Shouldn't it be 0?
Offline

The speed of your cannon ball would be your hypotenuse.
Your "x-velocity" should equal the Sine of your direction times speed
XV = ( Sine ( direction ) ) * ( 3 )
Y-velocity is the same but with cosine.
Offline
SeptimusHeap wrote:
Greatdane wrote:
Sine and cosine can specifically be used to determine a length based on an angle. I do believe that you can use this to find the best height and speed, and trajectory.
http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
http://scratch.mit.edu/projects/BATzerk/48863I downloaded the project, but I don't see any trig blocks, just your general math blocks, + _ * and /.
it will be in the dropdown for ([mathfunction] of (number))
Offline
Change X By sin of direction x velocity, y by cos!
Offline