0
我有一個由中心的x和y座標定義的正多邊形,邊的數量,邊的長度和從水平面的旋轉。它始終爲每個座標吐出零。下面的代碼:獲取正多邊形的頂點列表
public Point[] getPoints() {
Point[] points = new Point[n];
double radius = s/(2*Math.sin(Math.PI/n));
double angle = (Math.PI*2)/n;
points[0] = new Point((int)Math.round(r),0);
for(int i = 1; i < n; i++) {
points[i] = multiplyByRotationMatrix(points[i-1],angle);
System.out.println(points[i]);
}
for(int i = 0; i < n; i++) {
points[i].x += x;
points[i].y += y;
}
for(int i = 0; i < n; i++) {
points[i] = multiplyByRotationMatrix(points[i],r);
}
return points;
}
private Point multiplyByRotationMatrix(Point p, double angle) {
if(angle==0) return p;
Point2D pNew = new Point2D.Float();
pNew = AffineTransform.getRotateInstance(angle,p.x,p.y).transform(p, pNew);
System.out.println(pNew.toString() + " , " + p.x + "," + p.y);
return new Point((int)Math.round(pNew.getX()),(int)Math.round(pNew.getY()));
}
旋轉矩陣位實際上是在一些點旋轉矩陣,但我把它改成的AffineTransform,看看它是否會工作(它沒有)。什麼是更好的方式去做這件事?
似乎points'的'元素的值與變量'x'和回答'y '。他們的價值是什麼?他們在哪裏定義? – RealSkeptic
'x'和'y'在構造函數中被實例化。 –