0

I am rewriting a tree fractal code to draw L-Systems with only 1 long line for 3d spirographs, 3d architecture etc.

I have rotation errors: 90° angle Sin/Cos makes some angles with 45° and 135° instead of 90° Why?

//A recursive function used to draw the fractal tree
function drawTree( x1 : float,  y1 : float,  z1 : float,  y3 : float,  angle : float,  angle2 : float,  depth : int){

    if (depth != 0){

         var  x2  : float= x1 + (Mathf.Cos(angle * deg_to_rad) );
         var  z2  : float= z1 + (Mathf.Cos(angle2 * deg_to_rad) );
         var  y2  : float= y1 + (Mathf.Sin(angle * deg_to_rad) );
         var  y4  : float= y3 + (Mathf.Sin(angle2 * deg_to_rad) );

         var  n1 : float = (y3+y1);
         var  n2  : float= (y4+y2);

         if (depth > 1 ){drawLine2(x1, n1, z1, x2, n2, z2, depth);}

        if(depth%2 == 0)                            
        drawTree(x2, y2, z2, y4, rand_90_degrees_x4_function(depth) , 0  , depth - 1);
        else            
        drawTree(x2, y2, z2, y4, 0 , rand_90_degrees_x4_function(depth+2)  , depth - 1);

    }
}

Why are some angles not 90° at beginning and end: non 90' angle problems

bandybabboon
  • 2,210
  • 1
  • 23
  • 33
  • What is the value of _powerval_? – karatedog Jul 25 '14 at 08:04
  • sorry i forgot that from previous version of code, it was to change branch lengths.... i've managed to get this running in a random way for spirographs using drawTree( x2, y2, z2, y4, angle + 22.5 , angle2 + 10 , depth - 1 ); but i the angles are wonky and unpredictable. – bandybabboon Jul 25 '14 at 08:21
  • I'm checking this from mobile (no chance for testing) but at first sight I'd say you have a recursion problem. I'd suggest to fold out the recursive algorithm into a loop to detect the error(s) – karatedog Jul 25 '14 at 19:34
  • Thanks, i did as you suggested to unfold the recursion, and i changed the rotation to quaternions instead of sinus, it works fine. – bandybabboon Jul 25 '14 at 21:48

0 Answers0