我正在爲L-Systems創建一個Android應用程序,並且在旋轉矩陣後得到不同的行長度,這會導致不規則的分形。爲什麼我在Android中使用矩陣旋轉點時會得到不同的行長度,我該如何解決?
實施例:
正如你可以看到,旋轉線的長度而變化,以120°的旋轉的線比爲240°的旋轉的線短。
。
對於旋轉,我使用這些Android Matrix Operations基於this answer here點。 我正在圍繞它的起點旋轉一條線的終點。
代碼:
Matrix transform;
public Point rotate(Point angleP, Point p, float degrees) {
// This rotates around the previous Point by degrees
transform.setRotate(degrees, angleP.x, angleP.y);
// Create new float[] to hold the rotated coordinates
float[] pts = new float[2];
// Initialize the array with our Coordinate
pts[0] = p.x;
pts[1] = p.y;
// Use the Matrix to map the points
transform.mapPoints(pts);
// NOTE: pts will be changed by transform.mapPoints call
// after the call, pts will hold the new cooridnates
// Now, create a new Point from our new coordinates
Point newPoint = new Point((int)pts[0], (int)pts[1]);
// Return the new point
return newPoint;
}
的對應點+旋轉前五個點基於上述代碼:
- forward by 30pt, angle is: 0.0°, rotate/translate Point(384, 433) -> Point(384, 433)
- changed rotation by120.0 from 0.0->120.0
- forward by 30pt, angle is: 120.0°, rotate/translate Point(384, 403) -> Point(409, 447)
- changed rotation by-120.0 from 120.0->0.0
- forward by 30pt, angle is: 0.0°, rotate/translate Point(409, 417) -> Point(409, 417)
- changed rotation by-120.0 from 0.0->-120.0
- forward by 30pt, angle is: -120.0°, rotate/translate Point(409, 387) -> Point(383, 431)
- changed rotation by120.0 from -120.0->0.0
- forward by 30pt, angle is: 0.0°, rotate/translate Point(383, 401) -> Point(383, 401)
調試 - 日誌中的前五個線(最多 - >右 - >向上 - >左 - >向上,相同的圖片):
line# line-start line-end line-length
line0 from 384/463 to 384/433, length: 30.0
line1 from 384/433 to 409/447, length: 28.653097563788805
line2 from 409/447 to 409/417, length: 30.0
line3 from 409/417 to 383/431, length: 29.5296461204668
line4 from 383/431 to 383/401, length: 30.0
有問題IM是,我想/需要的RESU使線條長度相等,但由於某些原因,旋轉120°的線比旋轉-120°的線要小。
我的猜測是,不同的線路長度舍入誤差的結果,但我不知道我怎麼會開始修復這一點。
任何幫助或指針,將不勝感激。