0

Now i draw pictures in circle by formula :

     float x = CIRCLE_RADIUS *  (float) Math.sin(2f * Math.PI * drawSquareIndex / ITEMS_COUNT + angle) * 1.75f;

where x - is a X point of circle item.

And i have a circle.

enter image description here

but i want to draw pictures on ellipse. What the formula i need to use?

enter image description here

How i can do that?

P.S. sorry about quality. Make a question from phone.

Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
  • I am not sure I understand, do you mean you want to find the [equation](http://en.wikipedia.org/wiki/Ellipse#Equations) for ellipses? Or maybe do you want to find the equation based on the points? – Tonio Mar 26 '14 at 14:10

1 Answers1

2

You can use parametric ellipse equaition (a = b is a case of cirle):

x = a * cos(t)
y = b * sin(t)
t = 0..2*PI

In your case

  // Pseudo code
  for (double t = 0; t < 2 * PI; t += 0.001) { // <- or different step
    double x = RadiusX * Math.Cos(t);
    double y = RadiusY * Math.Sin(t);

    Paint(x, y);
  }
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • That's if the ellipse is in canocical form, otherwise you need to take into account the center `(x_c, y_c)` of the ellipse and the angle `phi` between the `X` axis and the major axis of the ellipse. Then, `x = x_c + a * cos(t) * cos(phi) - b * sin(t) * sin(phi)` and `y = y_c + a * cos(t) * sin(phi) - b * sin(t) * cos(phi)` ([ref](http://en.wikipedia.org/wiki/Ellipse#General_parametric_form)) – Tonio Mar 26 '14 at 14:24
  • @Tonio: Yes, you're quite right: shifts by x and y axises and rotation transformations. But according the picture in the question it is the simplest (canonical) ellipse that's required. So I've omited x = x + dx; y = y + dy; and the rotation matrix – Dmitry Bychenko Mar 26 '14 at 14:27
  • 1
    That's true, I added it in the comment for reference. By the way, I made a mistake in my expressions of `x` and `y`, for reference, these are: `x = x_c + a * cos(t) * cos(phi) - b * sin(t) * sin(phi)` and `y = y_c + a * cos(t) * sin(phi) + b * sin(t) * cos(phi)`. Which is probably why manipulating transformation matrices -- as you suggested -- helps to get clarity in equations and helps prevent sign mistakes ;) – Tonio Mar 26 '14 at 14:33