home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / fractal / fdesi313 / fdes13s / fdesequa.c < prev    next >
Text File  |  1989-09-28  |  2KB  |  78 lines

  1. /*
  2.         Equation solving for Triangle Transformations
  3. */
  4. #include <float.h>
  5. #include "fdestria.h"
  6. #include "fdesign.h"
  7. #include "fdesfile.h"
  8. #include "fdesmenu.h"
  9. #include "fdesmous.h"
  10. #include "fdesplot.h"
  11.  
  12.  
  13. /************************************************************************
  14.         SOLVING EQUATIONS FOR TRIANGLE TRANSFORMATION TO IFS CODE
  15. ************************************************************************/
  16. /*
  17.     Compute the IFS array for the given triangles
  18. */
  19. float det(float a, float b, float c, float d)
  20. {
  21.     return(a*d-b*c);
  22. }
  23. float solve3(float x1,float x2,float x1h,float y1,float y2,float y1h,
  24.          float z1,float z2,float z1h, float *a,float *b,float *e)    /* solve linear system */
  25. {
  26.     /*  Format for the equations is this:
  27.         x1*a + x2*b + e = x1h
  28.         y1*a + y2*b + e = y1h
  29.         z1*a + z2*b + e = z1h
  30.     */
  31. float det1;
  32.     det1 = x1 * det(y2,1.0,z2,1.0) - x2 * det(y1,1.0,z1,1.0) + 1*det(y1,y2,z1,z2);
  33.     if (det1 == 0.0) return (det1);
  34.     *a = (x1h * det(y2,1.0,z2,1.0) - x2 * det(y1h,1.0,z1h,1.0) + 1*det(y1h,y2,z1h,z2))/det1;
  35.     *b = (x1 * det(y1h,1.0,z1h,1.0) - x1h * det(y1,1.0,z1,1.0) + 1*det(y1,y1h,z1,z1h))/det1;
  36.     *e = (x1 * det(y2,y1h,z2,z1h) - x2 * det(y1,y1h,z1,z1h) + x1h*det(y1,y2,z1,z2))/det1;
  37.     return(det1);
  38. }
  39.  
  40. /*
  41.     compute IFS of triangle and place codes at IFS pointer
  42.     t1 is the transform triangle, t0 is the reference triangle
  43. */
  44. void IFS_compute(float *IFS, triangle *t1, triangle *t0)
  45. {
  46.         solve3((*t0).col[0],(*t0).row[0],(*t1).col[0],
  47.                (*t0).col[1],(*t0).row[1],(*t1).col[1],
  48.                (*t0).col[2],(*t0).row[2],(*t1).col[2],
  49.            &IFS[0],&IFS[1],&IFS[4]);
  50.         solve3((*t0).col[0],(*t0).row[0],(*t1).row[0],
  51.                (*t0).col[1],(*t0).row[1],(*t1).row[1],
  52.                (*t0).col[2],(*t0).row[2],(*t1).row[2],
  53.            &IFS[2],&IFS[3],&IFS[5]);
  54.     }
  55. /*
  56.     compute IFS codes for all of the triangles
  57. */
  58. void IFS_compute_all(int howmany, triangle *t, triangle *t0)
  59. {
  60. int i;
  61. float total_area;
  62.     IFS[0] = howmany;
  63.     total_area = 0.0;
  64.     for (i=0; i<howmany; i++)
  65.     {
  66.         IFS_compute(&IFS[1+i*7],&t[i],t0);
  67.         /* pseudo-probability measure */
  68.         total_area += (IFS[1+i*7+6] = triangle_area(&t[i]));
  69.     }
  70.     /* normalize probabilities to 1.0 */
  71.     for (i=0; i<howmany; i++)
  72.     {
  73.         IFS[1+i*7+6] /= total_area;
  74.     }
  75. }
  76.  
  77.  
  78.