我有一个自定义椭圆,它有一个旋转方法:
import com.badlogic.gdx.math.Vector2;
public class BetterEllipse {
float centerx,centery,width,height;
int pointAmount;
//float vector array
Vector2[] border;
BetterEllipse(float cneterX,float centerY,float width_, float height_)
{
centerx=cneterX; centery=centerY;
width=width_; height=height_;
pointAmount=360;
border=new Vector2[pointAmount];
for(int n=0;n<pointAmount;n++)
{
double x=cneterX +(width_/2*Math.cos(n));
double y=centerY+ (height_/2*Math.sin(n));
border[n]=new Vector2((float)x,(float)y);
}
}
/**angle > 0 - rotates counter-clock, angle < 0 - rotate clock*/
public void rotate(float angle)
{
for(Vector2 point:border)
{
float newX=(float) ((point.x)*Math.cos(angle)-(point.y)*Math.sin(angle));
float newY=(float) ((point.x)*Math.sin(angle)+(point.y)*Math.cos(angle));
//after
point.x=newX;
point.y=newY;
}
}
}
椭圆旋转,但它也围绕点0,0运行。我想我必须把centerx放在rotate()中,但是无法计算如何。
答案 0 :(得分:0)
减去
后旋转center = 1/2 *(centerx + centery)
然后再将其添加到结果中。