だから私は楕円を持っています:
RADIUS_X = 100.0f;
RADIUS_Y = 30.0f;
この楕円に沿って3つのオブジェクトを均等に分散させたいのですが、オブジェクトを移動すると、他の2つのオブジェクトも同じ距離を移動します。
以前は、XとYの半径が同じだったとき、オブジェクトを移動するたびに、そのオブジェクトの角度と以前の角度の差を取得し、その差を使用して追加していました。他の2つのオブジェクトに。それは完全にうまくいきました
(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];
}
}