Hello,
I am trying to move an object in an ellipse. This is my code so far:
setLocation(c - (int) Math.ceil(Math.sqrt(a)), b);
while (xCoordinate < initialXCoordinate + horizontalDistance){
xCoordinate++;
yCoordinate = d + (int) Math.ceil(Math.sqrt(b*b*(1 - (xCoordinate/a)*(xCoordinate/a))));
setLocation(xCoordinate, yCoordinate);
}
while (xCoordinate > initialYCoordinate - horizontalDistance){
xCoordinate--;
yCoordinate = d + (int) Math.ceil(- Math.sqrt(b*b*(1 - ((xCoordinate-c)/a)*((xCoordinate-c)/a))));
setLocation(xCoordinate, yCoordinate);
}
}
The code follows the equation of an ellipse on the Cartesian Plane. By using a function, I am hoping to define the trajectory of the object. However, this method immediately sets the object to the coordinates (0, 0).
Does anyone know what is wrong with my method? Or if there is an easier way to draw an ellipse?

