2017-04-19 17 views
0

我正在为L-Systems创建一个Android应用程序,并且在旋转矩阵后得到不同的行长度,这会导致不规则的分形。为什么我在Android中使用矩阵旋转点时会得到不同的行长度,我该如何解决?

实施例:

Misaligned fractal

正如你可以看到,旋转线的长度而变化,以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°的线要小。

我的猜测是,不同的线路长度舍入误差的结果,但我不知道我怎么会开始修复这一点。

任何帮助或指针,将不胜感激。

回答

相关问题