Hello scratchers, im not really good at sine and cosine math concepts, so can someone show me how to use them? You can give an example of drawing a circle (and please explain why sine and cosine are used). Thank you with all my thanks
Offline
If you take an arbitrary angle that measures the offset from the x-axis (so, imagine angle = 0 is pointing straight right), you can take the sine or the cosine of the angle to give you a value. This value represents the length along the y (sine) or x (cosine) axis of a line drawn with that angle and a length of 1. For that reason, sin(angle)^2 + cos(angle)^2 = 1. Since drawing from (0, 0) to (cos(angle), sin(angle)) will always give you a line of length 1, you can draw a line with a length of 10 by going from the origin to (10 * cos(angle), 10 * sin(angle)). Does that make sense?
So, to make a circle, all we have to do is start with an angle variable, and increment it so that it moves all the way around a circle.
One thing to know: the "angle" argument that the sine and cosine functions take is not the same as "Scratch" angles, where 90 is right, 0 is up, etc. Here, 0 is right, 90 is up, 180 is left, and 270 (or, -90, equivalently). The sine and cosine functions don't worry about how many rotations you have completed. sin(270) is the same as sin(630), and even sin(990).
when gf clicked set [angle v] to [0] repeat(360) pen up go to x: (0) y: (0) pen down go to x: ((100) * ([cos v] of (angle))) y: ((100) * ([sin v] of (angle))) change [angle v] by (1) end
Offline
Thanks for the awesome explannation, but I have a question involving your equation, what is the *100 for?
Offline
BirdByte wrote:
ArloarLoLs wrote:
Thanks for the awesome explannation, but I have a question involving your equation, what is the *100 for?
100 is the radius of the circle.
Oh ok.
Offline
amcerbu wrote:
when gf clicked set [angle v] to [0] repeat(360) pen up go to x: (0) y: (0) pen down go to x: ((100) * ([cos v] of (angle))) y: ((100) * ([sin v] of (angle))) change [angle v] by (1) end
just by looking at your script I can tell it doesn't work. first of all your script would be drawing a big asterisk, not a circle, since you're telling it to draw lines from the center to a point on the circle, not the perimeter of the circle. also due to scratch's direction system, sin corresponds to x, not cos (but thats just nit-picking)
when gf clicked set [angle v] to [0] repeat (360) go to x: ((radius) * ([sin v] of (angle))) y: ((radius) * ([cos v] of (angle))) pen down change [angle v] by (1) end
Last edited by Wes64 (2012-08-29 12:45:55)
Offline
Wow, that was stupid of me. I can't believe I did that. Yeah, just get rid of the "go to x: 0, y: 0" block. And cos is x and sin is y, it's just that angle represents 90 - Scratch direction.
Last edited by amcerbu (2012-08-29 14:24:53)
Offline
amcerbu wrote:
Wow, that was stupid of me. I can't believe I did that. Yeah, just get rid of the "go to x: 0, y: 0" block. And cos is x and sin is y, it's just that angle represents 90 - Scratch direction.
X uses sine, y uses cosine.
Offline
Wes64 wrote:
amcerbu wrote:
when gf clicked set [angle v] to [0] repeat(360) pen up go to x: (0) y: (0) pen down go to x: ((100) * ([cos v] of (angle))) y: ((100) * ([sin v] of (angle))) change [angle v] by (1) endjust by looking at your script I can tell it doesn't work. first of all your script would be drawing a big asterisk, not a circle, since you're telling it to draw lines from the center to a point on the circle, not the perimeter of the circle. also due to scratch's direction system, sin corresponds to x, not cos (but thats just nit-picking)
when gf clicked set [angle v] to [0] repeat (360) go to x: ((radius) * ([sin v] of (angle))) y: ((radius) * ([cos v] of (angle))) pen down change [angle v] by (1) end
Are you sure its gonna draw an asterisk? XD
Offline
Leg: Either side of a right triangle that isn't the hypotenuse.
To go a little bit into detail about trig, not just scripting, there are three main functions (though there are many more), which all are focused around the same basis, which is the ratios of the sides of a right triangle. Sine, cosine, and tangent. These functions can also be used for non-right triangles, though you can only use them in certain formulas like the law of sines and the law of cosines. There's no law of tangents.
The ratios are:
Sine = opposite ÷ hypotenuse. Cosine = adjacent ÷ hypotenuse. Tangent = opposite ÷ adjacent. You can use the acronym: SOHCAHTOA (or sow-cah-tow-ah) to remember. (As long as you remember how to spell it.)
So, to explain, let's say there's a right triangle. Let's say it's a 30-60-90, which, of course, refers to the angles. First note that you shouldn't use the right angle. Just don't, you shouldn't have to. So you take the 30 degree angle and you want to find the sine of it, or (or sin(30.))
Because the sine of an angle is the side opposite the chosen angle over the hypotenuse, or longest side, the sine of 30 degrees would be 1/2. This (again, in a right triangle,) is because the ratio of the short leg of a 30-60-90 triangle, the side opposite the smallest angle, 30, to the hypotenuse of the triangle is 1:2.
If you want proof, use the Pythagorean Theorem, which you should know if you have any business messing with trig. Take an equilateral triangle with sides 2 and drop an altitude, perpendicularly bisecting the base (and the angle you drew it from.) You should have two 30-60-90 triangles with leg = 1 and hypotenuse 2. You're done. Also know that the second, longer leg will be the shorter leg times the square root of 3. (√3.) If you do it with trig, you'll get the same thing. Anyway, since you already know the sides of a 30-60-90 given one, trig is mostly for right triangles that aren't "special."
Zach
P.S. There is one more "special" right triangle called a 45-45-90, and it's the reason why the tangent of 45 is 1. You have two congruent angles, which according to the converse of the isosceles triangle theorem, means the two sides opposite them are congruent as well. (Not the base.) The tangent ratio is O/A, or the side opposite the given over the side adjacent to it, which IS NOT the hypotenuse. As I said, those two sides are congruent, so the ratio of the sides is 1/1, or just 1. Similarly to how the longer leg of a 30-60-90 is the short one times the square root of three, the hypotenuse of a 45-45-90 is either of the legs, which are the same, times the square root of TWO (√2.) You can prove that with the Pythagorean theorem.
That probably seemed a little crazy, but once you learn it in school it won't seem that ridiculous.
Last edited by noobydoobydoo (2013-03-28 20:47:42)
Offline