Finding a point along an oval

This is probably trivial for many of you, but I’m a bit stuck as to how to proceed. My ultimate goal with this is to have a collection of 2-6 round buttons that all appear equal distance apart on an oval path. When the user clicks on one button, it rotates to the front (while scaling larger) as the other buttons rotate with it along the orbital looking path.

The following code will find equidistant points along a circle, but how do you do this if you have an oval like this?:

ellipse = new Ellipse2D.Float(0, 0, 400, 50);

/******************************************************************/

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

public class Main {

private static List findPoints(int x, int y, int r, int n)    {
   List listOfPoints = new ArrayList();
   for (int i=0; i<n; i++) {
       listOfPoints.add(
               new Point(
                       (int)(x+r*Math.cos(Math.PI*i/n-Math.PI/2)), 
                       (int)(y+r*Math.sin(Math.PI*i/n-Math.PI/2))));
   }
   return listOfPoints;
}


public static void main(String[] args){
    System.out.println(findPoints(0, 0, 1, 4));
}

}

I think you can just scale one axis. Eg just having the circle centered around 0/0, multiply the y values with some other value and finally you add some x/y to move those values over to the spot where you want it to have. (Say its 640x480 you would add 320 to x and 240 to y).

I’m not sure I understand what you mean. Anyway you could give me a snippet of code to help explain?

listOfPoints.add(
new Point(
(int)(x+w0.5Math.cos(Math.PIi/n-Math.PI/2)),
(int)(y+h
0.5Math.sin(Math.PIi/n-Math.PI/2))));

Where w is the width and h is the height of the ellipse.

Scaling the axis will not result in equidistant points. I’d write a parametric representation of the oval, say


x = a cos(t)
y = b sin(t)

Then you cal calculate curve lengths using



                   /
                  |  //d      \2   /d      \2\1/2
                  |  ||-- x(t)|  + |-- y(t)| |    dt
                  |  \\dt     /    \dt     / /
                 /


(hope this is displayed correctly)

Thanks guys. Here is the code I’ve been using, I think this only gets the first 180 degrees, but it should be enough to get someone started if they are having the same problem I was:

private Point getPointOnEllipse(int i,int n,int x,int y,int radiusX,int radiusY) 
{
	x = (int) (x + (radiusX * Math.cos(Math.PI * i / n - Math.PI/2)));
	y = (int) (y + (radiusY * Math.sin(Math.PI * i / n - Math.PI/2)));
	return new Point(x, y);
}

Where radiusX and radiusY are the width and height of the bounding box, respectively. i is part of a for loop and n is the total number of points to check for.

That method will not generate equidistant points on the ellipse. Points near the minor axis of the ellipse will be farther apart due to the non-isotropic scaling.