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

#1 2011-01-29 09:43:56

rep353
Scratcher
Registered: 2010-03-22
Posts: 40

How to get angle of slope

Hey guys I have 2 points which I can get the slope of [m = y2 -y1 / x2 -x1]

My question is how to you get the angle of a line using slope?

I want another object to go parallel to this line.

Offline

 

#2 2011-01-29 09:54:56

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How to get angle of slope

To make an angle you need two intersecting lines, don't you?

But for what I assume you want, you could do the easy way (place a sprite at the first point, make it point towards the second point, and store the direction in a variable to get the direction of the parallel line), or the complex but efficient way, with this script:
http://i54.tinypic.com/vrx990.gif
Just make a sprite move in the direction this script calculates to get a parallel line.

Last edited by Kileymeister (2011-01-29 09:55:20)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#3 2011-01-29 11:18:47

rep353
Scratcher
Registered: 2010-03-22
Posts: 40

Re: How to get angle of slope

Thanks for that post the easy part was useful and easy to understand. Could you please briefly explain the second (harder) way as it has so many if and else statements :S

Offline

 

#4 2011-01-29 11:31:33

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How to get angle of slope

rep353 wrote:

Thanks for that post the easy part was useful and easy to understand. Could you please briefly explain the second (harder) way as it has so many if and else statements :S

Sure, this is getting into a bit complex stuff, you don't need to understand it all (you can just recreate the script and plug it in) but here's a short explanation.

The Main Part of the Script
Basically the main part of that script is the bottom half of the first if else piece.  Atan is a mathematical function, you don't need to know the exact function, but atan of x1-x2/y1-y2 gets direction out of a slope.

The reason there are two atans is because atan always turns out facing above 90 or -90 degrees, so for when the sprite needs to be facing down or below 90 or -90 degrees you rotate it 180 degrees (makes the sprite face backwards).  So if y1-y2 is less than 0 (meaning the line is going down) it turns 180 degrees.

The top half of the first if else script
The purpose of the top half of the first if else script is to make sure y1-y2 is not 0.  If it is 0, the atan part won't work because you need to divide a number by y1-y2 and you cannot divide by 0.

Because y1-y2=0 means the sprites are on the same vertical position, the sprite is only going to face right or left.  So it checks if the line is going right or left and faces that direction.

The point in direction 0 (up) part is for when both points of the line are in the exact same place.  This will rarely happen but when it does the sprite will just point up.
--------
Ok, that's a lot to chew, and is a bit confusing in some parts, but as I said you don't need to know all of this right now, you have plenty of time to learn.

Last edited by Kileymeister (2011-01-29 11:32:09)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#5 2011-01-29 14:45:25

rep353
Scratcher
Registered: 2010-03-22
Posts: 40

Re: How to get angle of slope

Thanks for that man. I really appreciate it.

Offline

 

#6 2011-01-29 21:19:38

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: How to get angle of slope

rep353 wrote:

Hey guys I have 2 points which I can get the slope of [m = y2 -y1 / x2 -x1]

Congratulations! You remember your algebra!

tongue

Offline

 

#7 2011-01-29 22:43:52

mathematics
Scratcher
Registered: 2009-03-01
Posts: 1000+

Re: How to get angle of slope

kayybee wrote:

rep353 wrote:

Hey guys I have 2 points which I can get the slope of [m = y2 -y1 / x2 -x1]

Congratulations! You remember your algebra!

tongue

Algebra? Isn't that Geometry?

Offline

 

#8 2011-01-29 23:05:52

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: How to get angle of slope

mathematics wrote:

kayybee wrote:

rep353 wrote:

Hey guys I have 2 points which I can get the slope of [m = y2 -y1 / x2 -x1]

Congratulations! You remember your algebra!

tongue

Algebra? Isn't that Geometry?

I think it is usually taught in Algebra, but is also used in Geometry.


http://i48.tinypic.com/2z5pqad.png

Offline

 

#9 2011-01-29 23:32:50

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: How to get angle of slope

scmb1 wrote:

mathematics wrote:

kayybee wrote:


Congratulations! You remember your algebra!

tongue

Algebra? Isn't that Geometry?

I think it is usually taught in Algebra, but is also used in Geometry.

I'm in algebra.

That's taught in Pre-algebra.
tongue

The algebra ones are standard:
Ax+By= C
And Point-Slope:
y-y1=m(x-x1)

tongue


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#10 2011-01-30 00:00:13

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: How to get angle of slope

bbbeb wrote:

scmb1 wrote:

mathematics wrote:


Algebra? Isn't that Geometry?

I think it is usually taught in Algebra, but is also used in Geometry.

I'm in algebra.

That's taught in Pre-algebra.
tongue

The algebra ones are standard:
Ax+By= C
And Point-Slope:
y-y1=m(x-x1)

tongue

I guess it depends on your school.  smile  I don't remember when I learned it.


http://i48.tinypic.com/2z5pqad.png

Offline

 

#11 2011-01-30 01:55:59

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: How to get angle of slope

bbbeb wrote:

scmb1 wrote:

mathematics wrote:


Algebra? Isn't that Geometry?

I think it is usually taught in Algebra, but is also used in Geometry.

I'm in algebra.

That's taught in Pre-algebra.
tongue

The algebra ones are standard:
Ax+By= C
And Point-Slope:
y-y1=m(x-x1)

tongue

Also, y=mx+b

Offline

 

#12 2011-01-30 16:25:25

rep353
Scratcher
Registered: 2010-03-22
Posts: 40

Re: How to get angle of slope

scmb1 wrote:

bbbeb wrote:

scmb1 wrote:

I think it is usually taught in Algebra, but is also used in Geometry.

I'm in algebra.

That's taught in Pre-algebra.
tongue

The algebra ones are standard:
Ax+By= C
And Point-Slope:
y-y1=m(x-x1)

tongue

I guess it depends on your school.  smile  I don't remember when I learned it.

We did slope of a line as trigonometry. The slope of a line is easy but there's some other stuff a lot more tricky to do. I'm doing higher level maths for my leaving cert (in Ireland) so I get to learn a lot of things in maths but trigonometry is the only thing I find useful.

Last edited by rep353 (2011-01-30 16:25:49)

Offline

 

#13 2011-01-31 21:41:59

jazed13
Scratcher
Registered: 2011-01-14
Posts: 20

Re: How to get angle of slope

this shizzies dont make sense whats a slope and what an atum whats with all the math,,, i just copied the velocity movment but i didnt get it  in the first place some one plaz answer this


Subscribe To The Scratch Tuturial Groups's Channel! http://www.youtube.com/user/Jazed13?feature=mhum
http://i1199.photobucket.com/albums/aa463/Jazed14/Subscribe.pnghttp://i1199.photobucket.com/albums/aa463/Jazed14/aspoKWEJ.gif

Offline

 

#14 2011-02-01 12:58:06

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How to get angle of slope

jazed13 wrote:

this shizzies dont make sense whats a slope and what an atum whats with all the math,,, i just copied the velocity movment but i didnt get it  in the first place some one plaz answer this

I'll assume you're younger and haven't taken some more advanced classes.

Slope is the ratio a line plotted on a linear graph moves vertically/horizontally.  However far a line moves vertically each time it goes horizontal 1 unit determines the slope.  It can also be written rise/run.

An atom (I'll assume you meant that) is a unit of matter so vastly small you can't see it.  It is considered the smallest unit if you don't count the subatomic particles that hold it together.  Atoms combine to make molecules, which combine to make larger units.  Everything is made from atoms.

Last edited by Kileymeister (2011-02-01 13:08:11)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#15 2011-02-01 13:06:56

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: How to get angle of slope

Kileymeister wrote:

jazed13 wrote:

this shizzies dont make sense whats a slope and what an atum whats with all the math,,, i just copied the velocity movment but i didnt get it  in the first place some one plaz answer this

I'll assume you're younger and haven't taken some more advanced classes.

Slope is the ratio a line plotted on a linear graph moves vertically/horizontally  However far a line moves vertically each time it goes horizontal 1 unit determines the slope.  It can also be written rise/run.

An atom (I'll assume you meant that) is a unit of matter so vastly small you can't see it.  It is considered the smallest unit if you don't count the subatomic particles that hold it together.  Atoms combine to make molecules, which combine to make larger units.  Everything is made from atoms.

Or, simply.

Slope = amount of change
Amount of rise
-------------------
Amount of run

Atom = 2nd most smallest unit of matter.


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#16 2011-02-01 16:05:24

ian528
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: How to get angle of slope

bbbeb wrote:

Kileymeister wrote:

jazed13 wrote:

this shizzies dont make sense whats a slope and what an atum whats with all the math,,, i just copied the velocity movment but i didnt get it  in the first place some one plaz answer this

I'll assume you're younger and haven't taken some more advanced classes.

Slope is the ratio a line plotted on a linear graph moves vertically/horizontally  However far a line moves vertically each time it goes horizontal 1 unit determines the slope.  It can also be written rise/run.

An atom (I'll assume you meant that) is a unit of matter so vastly small you can't see it.  It is considered the smallest unit if you don't count the subatomic particles that hold it together.  Atoms combine to make molecules, which combine to make larger units.  Everything is made from atoms.

Or, simply.

Slope = amount of change
Amount of rise
-------------------
Amount of run

Atom = 2nd most smallest unit of matter.

Quark= 1st smallest.
Also, I think jazed13 meant "What does atan mean", not atom.  wink

Offline

 

#17 2011-02-01 16:34:10

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How to get angle of slope

ian528 wrote:

Also, I think jazed13 meant "What does atan mean", not atom.  wink

Oh, you're probably right.  Let me break that down too.

Atan is the inverse of the function tangent.

Tangent takes the amount in degrees of an angle of a triangle and gives you the length of the opposite side to the angle divided by the adjacent side to the angle, without using the hypotenuse.

Atan (written correctly as tan^-1), being tangent's inverse, takes the length of the opposite side to the angle divided by the adjacent side to the angle to get the amount in degrees of the angle.

In scratch atan and tangent are used often for direction equations.

Last edited by Kileymeister (2011-02-01 16:36:02)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

Board footer