返回列表 发帖

易楼易码范例代码之曲线绘制

本帖最后由 liujing 于 2012-10-15 16:32 编辑

  1. //抛物曲线[Parabola]
  2. double dTSt = -10.0;
  3. double dTEd = 10.0;
  4. double dTol = 0.1;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double x= t;
  9. double y= pow(t,2);
  10. double z= 0;
  11. if(fabs(t - dTSt) < ZERO)
  12. {
  13.   ptSt = point(x, y, z);
  14. }
  15. else
  16. {
  17.   ptEd = point(x, y, z);
  18.   line(ptSt, ptEd);
  19.   ptSt = ptEd;
  20. }
  21. }
复制代码



  1. //接触网曲线[Catenary Curve]
  2. double dTSt = -10.0;
  3. double dTEd = 10.0;
  4. double dTol = 0.1;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=50.0;
  9. double x= t;
  10. double y=a*cosh(t/a);
  11. double z= 0;
  12. if(fabs(t - dTSt) < ZERO)
  13. {
  14.   ptSt = point(x, y, z);
  15. }
  16. else
  17. {
  18.   ptEd = point(x, y, z);
  19.   line(ptSt, ptEd);
  20.   ptSt = ptEd;
  21. }
  22. }
复制代码


  1. //圆柱螺旋线[Circular Helix]
  2. double dTSt = 0.0;
  3. double dTEd = 10*PI;
  4. double dTol = 0.1;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=5.0;
  9. double c=20.0;
  10. double x= a*sin(t);
  11. double y= a*cos(t);
  12. double z= t/(2*PI*c);
  13. if(fabs(t - dTSt) < ZERO)
  14. {
  15.   ptSt = point(x, y, z);
  16. }
  17. else
  18. {
  19.   ptEd = point(x, y, z);
  20.   line(ptSt, ptEd);
  21.   ptSt = ptEd;
  22. }
  23. }
复制代码


  1. //椭圆螺旋[Elliptical helix]
  2. double dTSt = 0.0;
  3. double dTEd = PI;
  4. double dTol = 0.01;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double r1 = 10;
  9. double r2 = 6;
  10. double pitch = 2;
  11. double revs = 4;
  12. double u = 2*PI*revs*t;
  13. double x= r1*sin(u);
  14. double y= r2*cos(u);
  15. double z= revs*t*pitch;
  16. if(fabs(t - dTSt) < ZERO)
  17. {
  18.   ptSt = point(x, y, z);
  19. }
  20. else
  21. {
  22.   ptEd = point(x, y, z);
  23.   line(ptSt, ptEd);
  24.   ptSt = ptEd;
  25. }
  26. }
复制代码


  1. //锥形螺旋[Conical Helix]
  2. double dTSt = 0.0;
  3. double dTEd = 10*PI;
  4. double dTol = 0.01;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=0.5;
  9. double c=5.0;
  10. double z= t/(2*PI*c);
  11. double x= a* (t/(2*PI*c))*sin(t);
  12. double y= a* (t/(2*PI*c))*cos(t);
  13. if(fabs(t - dTSt) < ZERO)
  14. {
  15.   ptSt = point(x, y, z);
  16. }
  17. else
  18. {
  19.   ptEd = point(x, y, z);
  20.   line(ptSt, ptEd);
  21.   ptSt = ptEd;
  22. }
  23. }
复制代码


  1. //正弦波双曲面[Sine Wave on Hyperboloid]
  2. double dTSt = 0.0;
  3. double dTEd = 2*PI;
  4. double dTol = 0.001;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=10.0;
  9. double b=0.8;
  10. double c=0.3;
  11. double x= b*((1+c^2*((cos(a*t))^2))^0.5)*cos(t);
  12. double y= b*((1+c^2*((cos(a*t))^2))^0.5)*sin(t);
  13. double z=c*cos(a*t);
  14. if(fabs(t - dTSt) < ZERO)
  15. {
  16.   ptSt = point(x, y, z);
  17. }
  18. else
  19. {
  20.   ptEd = point(x, y, z);
  21.   line(ptSt, ptEd);
  22.   ptSt = ptEd;
  23. }
  24. }
复制代码


  1. //对数螺线[Logarithmic spiral]
  2. double dTSt = 0.0;
  3. double dTEd = 15*PI/2.0;
  4. double dTol = 0.1;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=0.1;
  9. double c=0.1;
  10. double e = 2. 7181459268252248640376646749131;
  11. double r=c*pow(e,(a*t));
  12. if(fabs(t - dTSt) < ZERO)
  13. {
  14.   ptSt = point();
  15.   move(ptSt, r, t);
  16. }
  17. else
  18. {
  19.   ptEd = point();
  20.   move(ptEd, r, t);
  21.   line(ptSt, ptEd);
  22.   ptSt = ptEd;
  23. }
  24. }
复制代码


  1. //阿基米德螺旋[Archimedean spiral]
  2. double dTSt = 0.0;
  3. double dTEd = 8*PI;
  4. double dTol = 0.05;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=10;
  9. double r=a*t;

  10. if(fabs(t - dTSt) < ZERO)
  11. {
  12.   ptSt = point();
  13.   move(ptSt, r, t);
  14. }
  15. else
  16. {
  17.   ptEd = point();
  18.   move(ptEd, r, t);
  19.   line(ptSt, ptEd);
  20.   ptSt = ptEd;
  21. }
  22. }
复制代码


  1. //费马的螺旋[Fermat's spiral]
  2. double dTSt = 0.0;
  3. double dTEd = 8*PI;
  4. double dTol = 0.05;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=10;
  9. double m=2;
  10. double r=a*pow(t,(1/m));

  11. if(fabs(t - dTSt) < ZERO)
  12. {
  13.   ptSt = point();
  14.   move(ptSt, r, t);
  15. }
  16. else
  17. {
  18.   ptEd = point();
  19.   move(ptEd, r, t);
  20.   line(ptSt, ptEd);
  21.   ptSt = ptEd;
  22. }
  23. }
复制代码


  1. //双曲螺旋[Hyperbolic spiral]
  2. double dTSt = 1;
  3. double dTEd = 8*PI;
  4. double dTol = 0.05;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=10;
  9. double m=2;
  10. double r=a*pow(t,(1/m));
  11. double a=10;
  12. double m=-1;
  13. double r=a*pow(t,(1/m));

  14. if(fabs(t - dTSt) < ZERO)
  15. {
  16.   ptSt = point();
  17.   move(ptSt, r, t);
  18. }
  19. else
  20. {
  21.   ptEd = point();
  22.   move(ptEd, r, t);
  23.   line(ptSt, ptEd);
  24.   ptSt = ptEd;
  25. }
  26. }
复制代码


  1. //Toroidial螺旋[Toroidial Spiral]
  2. double dTSt = 0.0;
  3. double dTEd = 2*PI;
  4. double dTol = 0.005;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=0.2;
  9. double b=0.8;
  10. double c=20;
  11. double x=(a*sin(c*t)+b)*cos(t);
  12. double y=(a*sin(c*t)+b)*sin(t);
  13. double z=a*cos(c*t);
  14. if(fabs(t - dTSt) < ZERO)
  15. {
  16.   ptSt = point(x, y, z);
  17. }
  18. else
  19. {
  20.   ptEd = point(x, y, z);
  21.   line(ptSt, ptEd);
  22.   ptSt = ptEd;
  23. }
  24. }
复制代码


  1. //抛物线螺旋[Parabolic Spiral]
  2. double dTSt = 0.0;
  3. double dTEd = 10*PI;
  4. double dTol = 0.005;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double a=0.5;
  9. double c=5.0;
  10. double x=a*sin(t);
  11. double y=a*cos(t);
  12. double z=t^2/(2*PI*c)^2;
  13. if(fabs(t - dTSt) < ZERO)
  14. {
  15.   ptSt = point(x, y, z);
  16. }
  17. else
  18. {
  19.   ptEd = point(x, y, z);
  20.   line(ptSt, ptEd);
  21.   ptSt = ptEd;
  22. }
  23. }
复制代码


  1. //回旋螺旋[Clothoid spiral]
  2. double dTSt = -10.0;
  3. double dTEd = 10.0;
  4. double dTol = 0.01;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double phi = 4;
  9. double u = t*phi;
  10. double u2 = pow(u,2);
  11. double u3 = pow(u,3);
  12. double a0 = 1;
  13. double a1 = 0.1765;
  14. double b0 = 2;
  15. double b1 = 2.524;
  16. double b2 = 1.886;
  17. double b3 = 0.803;
  18. double c0 = 1;
  19. double c1 = 0.506;
  20. double d0 = 1.414;
  21. double d1 = 2.054;
  22. double d2 = 1.79;
  23. double d3 = 1.1021;
  24. double ajk = (a0+a1*u)/(b0+b1*u+b2*u2+b3*u3);
  25. double rlm = (c0+c1*u)/(d0+d1*u+d2*u2+d3*u3);
  26. double v = PI*(ajk-u2)/2;
  27. double x= 1/2-rlm*sin(v);
  28. double y= 1/2-rlm*cos(v);
  29. double z= 0;
  30. if(fabs(t - dTSt) < ZERO)
  31. {
  32.   ptSt = point(x, y, z);
  33. }
  34. else
  35. {
  36.   ptEd = point(x, y, z);
  37.   line(ptSt, ptEd);
  38.   ptSt = ptEd;
  39. }
  40. }
复制代码


  1. //过渡螺旋度[Transition spiral, degree]
  2. double dTSt = -10.0;
  3. double dTEd = 10.0;
  4. double dTol = 0.01;
  5. point ptSt, ptEd;
  6. for(double t = dTSt; t <= dTEd; t += dTol)
  7. {
  8. double deg0 = 0;
  9. double deg1 = 20;
  10. double lngth = 250;
  11. double l = lngth*t;
  12. double u = (deg0*t+(deg1-deg0)/2*t*t)*lngth/100;
  13. double u2 = pow(u,2);
  14. double u3 = pow(u,3);
  15. double u4 = pow(u,4);
  16. double u5 = pow(u,5);
  17. double u6 = pow(u,6);
  18. double u7 = pow(u,7);
  19. double u8 = pow(u,8);
  20. double c0 = 100;
  21. double c1 = 0.5817764173;
  22. double c2 = 0.3046174198e-2;
  23. double c3 = 0.126585165e-4;
  24. double c4 = 0.429591539e-7;
  25. double c5 = 0.122691057e-9;
  26. double c6 = 0.301987076e-12;
  27. double c7 = 0.652559e-15;
  28. double c8 = 0.135721e-17;
  29. double x= l*(c0-c2*u2+c4*u4-c6*u6+c8*u8)/100;
  30. double y= l*(c1*u-c3*u3+c5*u5-c7*u7)/100;
  31. double z= 0;
  32. if(fabs(t - dTSt) < ZERO)
  33. {
  34.   ptSt = point(x, y, z);
  35. }
  36. else
  37. {
  38.   ptEd = point(x, y, z);
  39.   line(ptSt, ptEd);
  40.   ptSt = ptEd;
  41. }
  42. }
复制代码

返回列表