Discuss Scratch

JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

Hi there - computer nerd here, trying to help someone I know with a Scratch program. My issue is that in Scratch, the pixels/steps have me a little confused.

I'm trying to draw a circle inscribed in an equilateral triangle, as is described here: https://www.youtube.com/watch?v=mulFsXCBw80

At around 3:28 he comes to the conclusion that the relationship between the circle's radius “r” and the triangle's side length “s” is:
s = 2*r*sqrt(2)
Or alternatively:
r = s / 2 * sqrt(2)

So, I have a block that can draw a triangle given a sidelength (repeats this three times: turn 120 degrees, move the given sidelength). Now I'm trying to draw the circle inside of it.

Let's say the triangle has a side length of 150 - that makes a nice sized triangle that fits within the scratch window. Using the formula above, that means that the radius of the circle should be ~53.

I have another block that draws a circle, given variable “Z” (repeats this 360 times: turn 1 degree, move Z steps). This works, so long as Z is quite small. If the circle starts at (0,0), basically nothing larger than 2 will work.


So, now I have to scale my circle radius of ~53 to something that will fit within the canvas, but will accurately be circumscribed within the triangle. How can I do that?
JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

I redid the script on this account quickly, hopefully it helps you understand what I'm trying to do: https://scratch.mit.edu/projects/54346878


I draw the triangle, then use a block to draw the circle, of size Z. I previously calculated (correctly, I hope) the radius of the circle, and now I need to convert that radius (~53) into something that makes sense for the DrawCircle block (has to be less than 1 to even fit inside the triangle).
deck26
Scratcher
1000+ posts

Drawing a Triangle and a Circle - Scaling Issues

What you could do is the following

go to the centre
then, in a loop (360)

move 53 steps, make a mark (perhaps with stamp), move -53 steps, turn 1 degree
JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

I can't use a stamp - has to be with the pen (as per the project instructions).


But as for your idea, I made a new project (available here: http://scratch.mit.edu/projects/54360680

I changed the old DrawCircle block (which is still available, but now named DrawCircleOld.

Within “DrawCircle”, I start out in the center of the triangle, which should be the center of the circle as well. But I have to move to the left by the value of Z in order to get the circle centered. I put the pen down, then, in a loop (360), I do what you said - move Z steps (where Z is 53), then move -53 steps, then turn 1 degree.

Unfortunately, this makes the circle still slightly larger than the triangle - I'm not really sure how though, given the calculation I did above. Based on the video I posted, the formula:

s = 2*r*sqrt(2)

is satisfied by the equation

150 = 2 * 53.033009 * sqrt(2)

So I'm getting there with the circle drawing (thanks!) but not quite for the inscribing

Last edited by JB92 (March 25, 2015 18:24:35)

JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

Just messing around with things, I found that the circle will fit if you multiple the value by 0.81 - http://scratch.mit.edu/projects/54364316/


I don't know the relevance of that number, and I can't just throw random numbers into the script to make things fit, but maybe it will help answer my question somehow
JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

Actually, this is getting weird now…still messing with things, 1/0.81 = 1.23456790123

Which is…weird.
deck26
Scratcher
1000+ posts

Drawing a Triangle and a Circle - Scaling Issues

If you scroll down the comments in the youtube video you'll see someone points out that the ratios for a 30:60:90 triangle are 1:root 3:2.

The video is wrong - if the hypoteneuse is 2x and the short side x then 4x^2 = x^2 + long side squared (Pythagoras) so the long side is x * sqrt(3)
JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

Sorry, still a little confused - the triangle in my project is equilateral, so there is no hypotenuse (due to there not being any 90 degree angles)
deck26
Scratcher
1000+ posts

Drawing a Triangle and a Circle - Scaling Issues

In the video you referred to he creates a right angled triangle (one triangle point, mid-point of one side, centre of triangle) which has angles 30:60:90 since he's bisecting the angle.

The triangle he creates is actually similar (in maths terminology so has same ratios/angles) to the triangle you get if you split your equilateral triangle down the middle. In the latter case, if you say the side is length 2 then the half-side is obviously length 1 and the line splitting the triangle is sqrt(3). In fact I think you're actually using this in your project already!

So instead of sqrt(2) the video and your project should use sqrt(3).
Psiborg
Scratcher
500+ posts

Drawing a Triangle and a Circle - Scaling Issues

JB92 wrote:

Actually, this is getting weird now…still messing with things, 1/0.81 = 1.23456790123

Which is…weird.

JB92 wrote:

Just messing around with things, I found that the circle will fit if you multiple the value by 0.81 - http://scratch.mit.edu/projects/54364316/


I don't know the relevance of that number, and I can't just throw random numbers into the script to make things fit, but maybe it will help answer my question somehow
I haven't looked at the maths but sqrt(2)/sqrt(3)=0.816 which might tie in with deck26's comments.
datab
Scratcher
20 posts

Drawing a Triangle and a Circle - Scaling Issues

Psiborg wrote:

I haven't looked at the maths but sqrt(2)/sqrt(3)=0.816 which might tie in with deck26's comments.

I don't know about you guys. But I am going to instantly follow anyone who just ‘knows’ that the relationship sqrt(2)/sqrt(3)=0.816. My math spider-sense tingles whenever I see sqrt(2) in a relationship

Cheers, Datab
Psiborg
Scratcher
500+ posts

Drawing a Triangle and a Circle - Scaling Issues

datab wrote:

I don't know about you guys. But I am going to instantly follow anyone who just ‘knows’ that the relationship sqrt(2)/sqrt(3)=0.816. My math spider-sense tingles whenever I see sqrt(2) in a relationship

Cheers, Datab


When I said I hadn't looked at the maths, I meant the equations involved in the geometry! I guessed that the 0.81 might be the ratio of root 2 to root 3 - but did use a calculator to check I'm afraid! I won't be offended if you “unfollow” after that startling admission…
JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

Wow. That was it.

This poor girl I'm tutoring made this whole Scratch program herself for a class, and it wasn't working - and she asked me to help her figure out why. Being someone who knows how to program, I assumed it was some error in her logic somewhere, or that she misunderstood how to use Scratch itself.

And yet, it turns out, the math in the video she used for the geometry was wrong. It's not even a geometry class, that was the easy part!

I removed the 0.81, and changed the sqrt(2) to sqrt(3), now the circle fits perfectly within the triangle. Thanks so much, everyone!
gtoal
Scratcher
1000+ posts

Drawing a Triangle and a Circle - Scaling Issues

JB92 wrote:

Hi there - computer nerd here, trying to help someone I know with a Scratch program. My issue is that in Scratch, the pixels/steps have me a little confused.

I'm trying to draw a circle inscribed in an equilateral triangle, as is described here: https://www.youtube.com/watch?v=mulFsXCBw80

At around 3:28 he comes to the conclusion that the relationship between the circle's radius “r” and the triangle's side length “s” is:
s = 2*r*sqrt(2)
Or alternatively:
r = s / 2 * sqrt(2)

So, I have a block that can draw a triangle given a sidelength (repeats this three times: turn 120 degrees, move the given sidelength). Now I'm trying to draw the circle inside of it.

There are a few triangle fillers on Scratch (such as this one https://scratch.mit.edu/projects/10119728/ ) which start by drawing an inscribed triangle. However for the special case of an equilateral triangle you just have to calculate the length of the line from the center to the middle of one side and use that as the radius.

If what you're asking for is a circle drawing procedure, those are available too… https://scratch.mit.edu/projects/49800724/

G

Last edited by gtoal (March 26, 2015 15:29:44)

JB92
New Scratcher
8 posts

Drawing a Triangle and a Circle - Scaling Issues

Thanks gtoal - I actually have it working no, but I'm looking at this project for future reference, it's awesome!
gesshoo9999
Scratcher
1 post

Drawing a Triangle and a Circle - Scaling Issues

what about turn 20 steps and move 120 steps

Powered by DjangoBB