Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Unsolved math problem! - defining the parameters of an ellipse...
- EmpowStudios
-
Scratcher
5 posts
Unsolved math problem! - defining the parameters of an ellipse...
wowSolved: http://scratch.mit.edu/projects/50183762/
The Dude Abides!
Colour me impressed.
Here's my interpretation of nXIII's mapping code; I've made a special case for circles because ideally you would want a rotated circle to be rendered identically at all rotations, but that doesn't in fact happen by default - there are slight variations in precisely which pixels are drawn at the top and sides of the circle.define Draw Rotated Ellipse (x) (y) (x axis) (y axis) (rotation) <filled?>
if <(x axis) = (y axis)> then
Draw Sheared Ellipse (x) (y) (x axis) (y axis) (filled?) (1) (0)
else
set [theta v] to ([atan v] of (((y axis) / (x axis)) * ((-1) * ([tan v] of (rotation)))))
set [shear: dx v] to (((x axis) * (([cos v] of (theta)) * ([cos v] of (rotation)))) - ((y axis) * (([sin v] of (theta)) * ([sin v] of (rotation)))))
set [shear: dy v] to (((x axis) * (([cos v] of (theta)) * ([sin v] of (rotation)))) + ((y axis) * (([sin v] of (theta)) * ([cos v] of (rotation)))))
set [shear: x axis v] to ([abs v] of (shear: dx))
set [shear: y axis v] to (((y axis) * (x axis)) / (shear: x axis))
Draw Sheared Ellipse (x) (y) (shear: x axis) (shear: y axis) (filled?) (shear: dx) (shear: dy)
end
I've modified the Ellipse Library so that the interface to drawing an ellipse uses axes and rotation and hides the internal shearing.
Thanks nXIII!
- Scratch_inno
-
Scratcher
9 posts
Unsolved math problem! - defining the parameters of an ellipse...
agreed! wow wow
- WO997
-
Scratcher
64 posts
Unsolved math problem! - defining the parameters of an ellipse...
Can anyone help me with https://scratch.mit.edu/projects/64850000/#player ? It should draw an ellipse in goes through 2 balls you see on the screen. I need it to draw circles in my 3d engine. For more informations reply 

- gtoal
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
Can anyone help me with https://scratch.mit.edu/projects/64850000/#player ? It should draw an ellipse in goes through 2 balls you see on the screen. I need it to draw circles in my 3d engine. For more informations reply
What he wants to do is similar to the original thread here. It boils down to specifying an ellipse one way and mapping that to drawing code.
Specifically what he is trying to do is draw 2D circles that exist in a 3D world. The circles can have any orientation in the 3D world. His specific example is wheels of a car. So first he specifies the circles which he's doing in terms of a center point (in x y z coordinates) and two points on the circumference (also in x y z coordinates).
He then wants to transform that to the view display via the usual 3D -> 2D transformation matrix. This will be displayed as an ellipse, and I think he's looking for a shortcut to make that transformation directly without having to transform every point on the ellipse's circumference.
For example, imagine this project: https://scratch.mit.edu/projects/859230/ but with a circle drawn on each of the faces of the cube. For simplicity, imagine the circle fits the square sides exactly and touches at 4 points. That gives you four fixed points on the circle that *ought* to be relatively easily transformed to corresponding points on the transformed ellipse, though with the rotations and yaw etc of the 3D -> 2D transformation, I don't expect those points to map to anything as simple as say the major and minor axis intersections of the ellipse? Or will they?
G
- TheLogFather
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
Just thought I'd note that I gave a point-by-point algorithm to draw the 2d projection of a 3d circle on WO997's project.
The key trick is to note that the circle's normal, drawn pointing from its centre, happens to project into 2d right on top of the desired ellipse minor axis (as long as you're not looking straight at the circle, in which case it's a trivial projection of the circle as a circle rather than ellipse).
That means you can find the direction of the ellipse minor axis by taking the projection of the circle's centre point and the projection of a point just ‘above’ or ‘below’ the circle (in the direction of the normal, either +ve or -ve). The second of those points lies in the same direction, from the first one, as the minor axis.
Once you have that, the rest is pretty simple… You know the length of the major axis, because it's (approximately) the usual radius-of-circle/distance projection formula. You know the ratio of the minor to major axis lengths (it's the cosine of the circle's tilt angle relative to the viewer, which just comes from the dot-product of the unit normal with the unit vector in the direction of the vector joining viewer to circle'e centre). And you know the direction of the major axis (it's 90 degrees from the direction of the minor axis, which we know).
If you want a bigger challenge, where the above simplifying trick isn't available, try figuring out the 2d projection of an ellipse in 3d space…
The key trick is to note that the circle's normal, drawn pointing from its centre, happens to project into 2d right on top of the desired ellipse minor axis (as long as you're not looking straight at the circle, in which case it's a trivial projection of the circle as a circle rather than ellipse).
That means you can find the direction of the ellipse minor axis by taking the projection of the circle's centre point and the projection of a point just ‘above’ or ‘below’ the circle (in the direction of the normal, either +ve or -ve). The second of those points lies in the same direction, from the first one, as the minor axis.
Once you have that, the rest is pretty simple… You know the length of the major axis, because it's (approximately) the usual radius-of-circle/distance projection formula. You know the ratio of the minor to major axis lengths (it's the cosine of the circle's tilt angle relative to the viewer, which just comes from the dot-product of the unit normal with the unit vector in the direction of the vector joining viewer to circle'e centre). And you know the direction of the major axis (it's 90 degrees from the direction of the minor axis, which we know).
If you want a bigger challenge, where the above simplifying trick isn't available, try figuring out the 2d projection of an ellipse in 3d space…

Last edited by TheLogFather (June 1, 2015 10:43:36)
- gtoal
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
What he wants to do is similar to the original thread here. It boils down to specifying an ellipse one way and mapping that to drawing code.
Specifically what he is trying to do is draw 2D circles that exist in a 3D world. The circles can have any orientation in the 3D world. His specific example is wheels of a car. So first he specifies the circles which he's doing in terms of a center point (in x y z coordinates) and two points on the circumference (also in x y z coordinates).
He then wants to transform that to the view display via the usual 3D -> 2D transformation matrix. This will be displayed as an ellipse, and I think he's looking for a shortcut to make that transformation directly without having to transform every point on the ellipse's circumference.
For example, imagine this project: https://scratch.mit.edu/projects/859230/ but with a circle drawn on each of the faces of the cube. For simplicity, imagine the circle fits the square sides exactly and touches at 4 points. That gives you four fixed points on the circle that *ought* to be relatively easily transformed to corresponding points on the transformed ellipse, though with the rotations and yaw etc of the 3D -> 2D transformation, I don't expect those points to map to anything as simple as say the major and minor axis intersections of the ellipse? Or will they?
G
Is @nXIII still around? Here's WO997's problem simplified: https://scratch.mit.edu/projects/70314862/
We need to determine the parameters of the ellipse that fits inside the quad. And then draw it, but that part is solved from our previous project.
So, four lines that touch the ellipse at a tangent - I think that's enough to determine a single unambiguous solution, right?
G
- nXIII
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
Is @nXIII still around? Here's WO997's problem simplified: https://scratch.mit.edu/projects/70314862/A quick Google turned up this, which shows that ellipses remain ellipses under projective transformation (i.e., when mapped to any convex quadrilateral) and demonstrates how to obtain the parameters of an ellipse so transformed.
We need to determine the parameters of the ellipse that fits inside the quad. And then draw it, but that part is solved from our previous project.
So, four lines that touch the ellipse at a tangent - I think that's enough to determine a single unambiguous solution, right?
- gtoal
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
Is @nXIII still around? Here's WO997's problem simplified: https://scratch.mit.edu/projects/70314862/A quick Google turned up this, which shows that ellipses remain ellipses under projective transformation (i.e., when mapped to any convex quadrilateral) and demonstrates how to obtain the parameters of an ellipse so transformed.
We need to determine the parameters of the ellipse that fits inside the quad. And then draw it, but that part is solved from our previous project.
So, four lines that touch the ellipse at a tangent - I think that's enough to determine a single unambiguous solution, right?
Perfect! That is exactly it!
thanks
G
- fsih
-
Scratcher
1 post
Unsolved math problem! - defining the parameters of an ellipse...
Hey, I wanted to let you guys know that your work on drawing rotated ellipses helped me a ton, and the code for drawing ovals in the new bitmap editor in Scratch 3.0 is based on work in this thread!
Here it is in code: https://github.com/fsih/scratch-paint/blob/5f74996a7f0637a3377b4407f8573c7b8df95c3c/src/helper/bitmap.js#L205
And here it is in action (you'll have to switch to the costumes tab and click convert to bitmap): https://preview.scratch.mit.edu/
Thank you so much! The scratch team was so excited when the algorithms we were looking for were right here on Scratch
Here it is in code: https://github.com/fsih/scratch-paint/blob/5f74996a7f0637a3377b4407f8573c7b8df95c3c/src/helper/bitmap.js#L205
And here it is in action (you'll have to switch to the costumes tab and click convert to bitmap): https://preview.scratch.mit.edu/
Thank you so much! The scratch team was so excited when the algorithms we were looking for were right here on Scratch

- gtoal
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
And here it is in action (you'll have to switch to the costumes tab and click convert to bitmap): https://preview.scratch.mit.edu/Very cool! Thanks for letting us know!
Thank you so much! The scratch team was so excited when the algorithms we were looking for were right here on Scratch
- gtoal
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
In case anyone ever comes back to this discussion, it occurred to me recently that the concept of applying a shear to a circle (and nXIII's formula for mapping the ellipse specifications, which can be used to determine the original circle and the shear to be applied) can be used to generate a new proof for the exact formula for the circumference of an ellipse (and the lesser problem, the area of an ellipse: it is the same as the circle before shearing, so pi*r^2 with r (ie the unsheared circle) being derived from nXIII's formula).
- Hardmath123
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
How does the circumference proof work? Isn't there in general no closed form?
- gtoal
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
How does the circumference proof work? Isn't there in general no closed form?'no closed form' just means no formula that doesn't involve an infinite sum of terms.
But 2*pi*r also involves an infinite sum of terms, we just call it ‘pi’ for short.
Consider this: an ellipse is a circle which is stretched on one axis, lets say x, by lets say 50%. the perimeter of that stretched circle is the y component of the circle's perimeter plus the x component of the circle's perimeter plus 50%.
And by shearing that axis-aligned ellipse in y we get our arbitrary ellipse. same deal.
nXIII's formula lets us map the traditionally-specific arbitrary ellipse to the axis-aligned ellipse from which it can be formed by shearing.
Unstretching that axis-aligned ellipse back to a circle is trivial, and we know the circumference of that circle.
So although I don't have the skill to work it all out in detail, I'm fairly sure these steps can be used to recreate the exact formula for the perimeter of an ellipse. Because the arbitrary shearing thing that nXIII pinned down is recent, I doubt very much this was the original basis of the proof for that formula, hence why I think there's a new proof here.
- Hardmath123
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
Consider this: an ellipse is a circle which is stretched on one axis, lets say x, by lets say 50%. the perimeter of that stretched circle is the y component of the circle's perimeter plus the x component of the circle's perimeter plus 50%.
Is this true? I'm not quite sure what you mean here (what is the “x component” of a perimeter?), but in any case in general I don't think this is how perimeters transform under linear transformations.
- gtoal
-
Scratcher
1000+ posts
Unsolved math problem! - defining the parameters of an ellipse...
Consider this: an ellipse is a circle which is stretched on one axis, lets say x, by lets say 50%. the perimeter of that stretched circle is the y component of the circle's perimeter plus the x component of the circle's perimeter plus 50%.
Is this true? I'm not quite sure what you mean here (what is the “x component” of a perimeter?), but in any case in general I don't think this is how perimeters transform under linear transformations.
break it down into infinitesimals - treat the circle as a regular polygon with infinite sides each of length 0. So any one segment is a triangle where the hypotenuse is on the perimeter and the x and y axes are the sin and cos of the angle to that segment. If you scale one axis linearly and keep the other constant, what happens to the scaled hypotenuse?
- Discussion Forums
- » Advanced Topics
-
» Unsolved math problem! - defining the parameters of an ellipse...







