Итак, у меня есть эллипс с:
RADIUS_X = 100.0f;
RADIUS_Y = 30.0f;
Я хочу равномерно распределить 3 объекта по этому эллипсу, и когда я перемещаю объект, другие 2 объекта также перемещаются на такое же расстояние.
Раньше, когда у меня был один и тот же радиус для X и Y, каждый раз, когда я перемещал объект, я брал полученную разницу углов этого объекта и его предыдущего угла от того, где он был раньше, тогда я использовал эту разницу чтобы добавить его к двум другим объектам. Это прекрасно работало, потому что
(X,Y) = (cos(angleDifference)*RADIUS_X ,sin(angleDifference)*RADIUS_Y)..
Но теперь, когда у меня есть RADIUS_X
и RADIUS_Y
, которые не совпадают, это не так хорошо работает.
Код ниже:
RADIUS_Y = 30.0f;
RADIUS_X = 100.0f;
float oldAngle = [Math arcTangent:[mainVisual getYCenter] X:[mainVisual getXCenter]]; // This just gets the angle of the main object.
float newAngle = -1.57; // This is the angle I want the main visual to move to
float tempAngle = newAngle - oldAngle; // I use tempAngle as the difference.
// Get it's (X,Y) coordinate with the new centered angle.
float yPosition = [Math sin:newAngle]*RADIUS_Y;
float xPosition = [Math cos:newAngle]*RADIUS_X;
// Set the main visual to the center.
[self setPosition:mainVisual :yPosition :xPosition];
// for even movement along the circle.
// iconObjectList = list of visuals(objects).
for (int i=0; i < [iconObjectList count]; i++)
{
Visual* v = [[iconObjectList objectAtIndex:i]getVisual];
if(v != mainVisual) // Because I have already set the main visual
{
float xPos = [v getXCenter];
float yPos = [v getYCenter];
float angle = [Math arcTangent:yPos X:xPos]; //This just gets the angle
angle += tempAngle; // This is where I added the difference to the current visuals angle.
// The code below is where i believe the problem is.
float yPosition = [Math sin:angle]*RADIUS_Y;
float xPosition = [Math cos:angle]*RADIUS_X;
[self setPosition:v :yPosition :xPosition];
}
}