-2
def curve(t, radiusX, radiusY):
    x = sin(t*pi/2) * radiusX
    y = cos(t*pi/2) * radiusY
    return (x,y)    

Following Python pseudo-code will draw a part 1/4 of an ellipse.
However, I am looking to stop drawing at given Y, as I don't need full 1/4 of this ellipse.

Can this function be parametrized such that it will stop drawing at given Y, without affecting the curve < Y?

An alternative approach is to draw using the current function and then cut the resulting object to given max height from the bottom, which I am trying to simplify.

I think the direction of the solution is to keep y at constant step using y = t * radiusY while x should be a transformed formula that will tell us what's the proper x given our y?

1 Answers1

0

Use

def curve(phi, radiusX, radiusY):
    r = 1/sqrt( sin(phi)**2/radiusX**2 + cos(phi)**2/radiusY**2)
    x = sin(phi) * r
    y = cos(phi) * r
    return (x,y)    

and now phi represents the polar angle of the ellipse, with 0 at the 12 o'clock positon and moving clockwise. So if you only want 1/4 of an ellipse use phi = 0..pi/2

This follows the polar coordinate definition for a centered, axis-aligned ellipse

$$r(\theta)=\frac{1}{\sqrt{\frac{\sin^{2}\theta}{a^{2}}+\frac{\cos^{2}\theta}{b^{2}}}}$$

and then $x = r \sin \theta$ and $y = r \cos \theta$.

John Alexiou
  • 13,816