This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-11-04 19:05:40

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Converting direction to x/y velocity?

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.


http://i46.tinypic.com/dw7zft.png

Offline

 

#2 2011-11-04 20:56:30

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Converting direction to x/y velocity?

Sine, and cosine!

a topic on sine/cosine


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#3 2011-11-04 20:58:40

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Converting direction to x/y velocity?

More detail on how I could use it to help me, please?

Last edited by SeptimusHeap (2011-11-04 20:59:01)


http://i46.tinypic.com/dw7zft.png

Offline

 

#4 2011-11-04 21:17:31

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: Converting direction to x/y velocity?

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


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#5 2011-11-05 08:39:42

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Converting direction to x/y velocity?

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 /.


http://i46.tinypic.com/dw7zft.png

Offline

 

#6 2011-11-05 08:43:16

resistance
Scratcher
Registered: 2011-10-30
Posts: 100+

Re: Converting direction to x/y velocity?

wut. i don't understand what you just said. what is sine and cosine?

this is offtopic but i love your dynamite mod


hand in mine into your icy blues, and then i'd say to you we could take to the highway with this trunk of ammunition too, i'd end my days with you in a hail of bullets

Offline

 

#7 2011-11-05 08:54:31

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Converting direction to x/y velocity?

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.


http://i46.tinypic.com/dw7zft.png

Offline

 

#8 2011-11-05 08:56:52

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Converting direction to x/y velocity?

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

 

#9 2011-11-05 08:56:57

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Converting direction to x/y velocity?

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.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#10 2011-11-05 09:01:05

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Converting direction to x/y velocity?

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...

tongue

We only spent 2 classes on trig last year, and that was over 6 months ago.

tongue

What I don't understand is the line just drawn thing that you said, and how I can implement this in code.


http://i46.tinypic.com/dw7zft.png

Offline

 

#11 2011-11-05 09:08:10

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Converting direction to x/y velocity?

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!  wink


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#12 2011-11-05 09:37:03

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Converting direction to x/y velocity?

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!  wink

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.


http://i46.tinypic.com/dw7zft.png

Offline

 

#13 2011-11-05 09:39:02

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Converting direction to x/y velocity?

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!  wink

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

 

#14 2011-11-05 09:40:24

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Converting direction to x/y velocity?

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!  wink

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).


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#15 2011-11-05 09:43:38

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: Converting direction to x/y velocity?

OK. 1 more thing, when I try 180 degrees, sine is like 1.2....

Why? Shouldn't it be 0?


http://i46.tinypic.com/dw7zft.png

Offline

 

#16 2011-11-05 10:05:31

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Converting direction to x/y velocity?

http://hyperphysics.phy-astr.gsu.edu/hbase/imgmth/ttrig.gif

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.


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#17 2011-11-05 11:43:03

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: Converting direction to x/y velocity?

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/48863

I 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))


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#18 2011-11-11 00:27:33

VirtualClown
Scratcher
Registered: 2011-08-05
Posts: 55

Re: Converting direction to x/y velocity?

Change X By sin of direction x velocity, y by cos!

Offline

 

Board footer