Discuss Scratch

Vaibhs11
Scratcher
1000+ posts

trigonometry on scratch

Chiroyce wrote:

-ElectronicArts- wrote:

intro creator time
yeah - almost every intro creator on scratch is obsessed with trig
But they off brand it to “math”, either because that's the “cooler” name or they are all 9-year-olds who don't know trig
The_Imaginarium
Scratcher
1000+ posts

trigonometry on scratch

Chiroyce wrote:

-ElectronicArts- wrote:

intro creator time
yeah - almost every intro creator on scratch is obsessed with trig
Or rather sinusoidal motion.
Vaibhs11
Scratcher
1000+ posts

trigonometry on scratch

bump
SavetheAtlantic
Scratcher
1000+ posts

trigonometry on scratch

You can easily make a 3D sphere function on Scratch using the trigonometry functions. Given a longitude λ and latitude φ, and longitude offsets of λ₀ and φ₁ (these will be used to rotate the sphere), you can use these transformation function to create an orthographic map projection, i.e. in layman's terms, a sphere as viewed without any perspective.


R is the radius of the sphere, so changing that will make the sphere bigger or smaller. Here's a simple demonstration I made: https://scratch.mit.edu/projects/754981645/ It's only a wireframe, but you can drag it around, and you can easily draw points, lines, and shapes on the sphere. If you could get your hands on some coastline or city data, you could make a nice globe on Scratch. All of the code was cut from a project I'm making, which I think is quite interesting, but I don't want to spoil anything.
gatgatcode
Scratcher
100+ posts

trigonometry on scratch

i made a bouncing ball with the sin wave ball
The_Imaginarium
Scratcher
1000+ posts

trigonometry on scratch

gatgatcode wrote:

i made a bouncing ball with the sin wave ball
nice
Epsilon_3
Scratcher
500+ posts

trigonometry on scratch

Trig is useful for 3d and projects like in my sig
Vaibhs11
Scratcher
1000+ posts

trigonometry on scratch

Epsilon_3 wrote:

Trig is useful for 3d and projects like in my sig
Why does everyone forget vectors and polar coordinates?
You can literally convert a line and and a given angle into cartesian coordinates using law of sines!!1!!1! (real)
Vaibhs11
Scratcher
1000+ posts

trigonometry on scratch

completeness wrote:

You're not actually using the law of sines, it's just the definition of sine
Though the components of a vector do form a right triangle, you can still call it the law of sines. The definition of sine only applies to right triangles, whereas the law of sines applies to any SAA triangle.
ISTILLMAKESTUFF
Scratcher
500+ posts

trigonometry on scratch

Vaibhs11 wrote:

Epsilon_3 wrote:

Trig is useful for 3d and projects like in my sig
Why does everyone forget vectors and polar coordinates?
You can literally convert a line and and a given angle into cartesian coordinates using law of sines!!1!!1! (real)
Ik i used that in on of my projects
Vaibhs11
Scratcher
1000+ posts

trigonometry on scratch

ISTILLMAKESTUFF wrote:

Ik i used that in on of my projects
I used it while making a project where you drive a car sprite across the screen, in JS
TheCreatorOfUnTV
Scratcher
1000+ posts

trigonometry on scratch

I think a better explanation of sines, cosines and tangents might be
“Where there is a triangle of length 1 and the angle given, sine is the vertical position of the unknown point, cosine is the horizontal position of the unknown point, and tangent is the slope of the hypotenuse, which goes to the unknown point.”
ThisIsTemp1
Scratcher
1000+ posts

trigonometry on scratch

Useful for making random clock positions that aren’t the most accurate.

Also has anyone mentioned

move () steps

Yet?
BigNate469
Scratcher
1000+ posts

trigonometry on scratch

ThisIsTemp1 wrote:

Useful for making random clock positions that aren’t the most accurate.

Also has anyone mentioned

move () steps

Yet?
Why?

It can be manually re-created, but it's a relatively unremarkable block otherwise. Yes, it uses trig, but it's existence is not itself remarkable.
jamesro75
Scratcher
2 posts

trigonometry on scratch

I've been looking at the “move _ steps” block. In most of my projects, I've avoided it because it seems like a terribly inefficient block.
But I just tested it against what should be an exact copy of it…

change x by (([sin] of (direction)::operators) * (steps))
change y by (([cos] of (direction)::operators) * (steps))

And I tested this against the move _ steps block. I tested both operations two million times, and the custom version took a noticeable amount of time but the scratch version finished almost instantly, as if it were a script without delays in it.

This means that rotation in scratch is optimized! I believe that it works by saving a normalized vector of the rotation too.
This makes even more sense because by using a dot product (four multiplications, two additions), the renderer could find the position of a rotated pixel on a sprite!
awesome-llama
Scratcher
1000+ posts

trigonometry on scratch

jamesro75 wrote:

And I tested this against the move _ steps block. I tested both operations two million times, and the custom version took a noticeable amount of time but the scratch version finished almost instantly, as if it were a script without delays in it.
Often most of the time difference is due to overhead. You are testing 1 block vs 8 plus the custom block.

The move block is implemented here
moveSteps (args, util) {
	const steps = Cast.toNumber(args.STEPS);
	const radians = MathUtil.degToRad(90 - util.target.direction);
	const dx = steps * Math.cos(radians);
	const dy = steps * Math.sin(radians);
	util.target.setXY(util.target.x + dx, util.target.y + dy);
}
jamesro75
Scratcher
2 posts

trigonometry on scratch

Doesn't everyone want this block?
move () steps forward and () steps to the side::motion
Well I found a way to define it!
define move (forward) (side) dir (sin) (cos) steps
go to x: ((((forward) * (sin)) - ((side) * (cos))) + (x position)) y: ((((forward) * (cos)) + ((side) * (sin))) + (y position))
This is useful for drawing custom lines with pen! (Like zig-zigs, dotted, ect)
set [dx v] to ((x2) - (x1))
set [dy v] to ((y2)-(y1))
set [dist v] to ([sqrt v] of (((dx) * (dx)) + ((dy) * (dy))))
set [sin v] to ((dx) / (dist))
set [cos v] to ((dy) / (dist))
And after this setup, do can make the custom line drawing script (example below is zig-zag)
go to x: [x1] y: [y1]
move [0] [-5] dir (sin) (cos )steps::custom
pen down
repeat until <(dist) < [0]>
move [5] [10] dir (sin) (cos) steps::custom
move [5] [-10] dir (sin) (cos) steps::custom
change [dist v] by [-10]
end
pen up

Last edited by jamesro75 (Yesterday 18:32:43)

Powered by DjangoBB