所以我有一个椭圆:
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];
}
}