Guest User

Untitled

a guest
Apr 25th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. //Using tangents
  2.  
  3. #include<iostream>
  4. #include "graphics.h"
  5. //#include"DDALine.h"
  6. using namespace std;
  7.  
  8. //float P0x = 100, P0y = 100, P1x = 150, P1y = 50, P2x = 250, P2y = 200, P3x = 350, P3y = 40, Px= 0, Py = 0, Pz = 0;
  9. //float P0x = 40, P0y = 250, P1x = 40, P1y = 200, P2x = 40, P2y = 150, P3x = 40, P3y = 100, Px= 0, Py = 0, Pz = 0;
  10.  
  11. void calcP(float P0x, float P0y, float R0x, float R0y, float P1x, float P1y, float R1x, float R1y, float Px, float Py, float t){
  12. Px = (2 * t * t* t -3*t*t +1)*P0x + ( t*t*t - 2 *t*t +t)*R0x + (-2 * t*t*t + 3*t*t )*P1x +(t*t*t -t*t )*R1x;
  13. Py = (2 * t * t* t -3*t*t +1)*P0y + ( t*t*t - 2 *t*t +t)*R0y + (-2 * t*t*t + 3*t*t )*P1y +(t*t*t -t*t )*R1y;
  14. putpixel(Px, Py, WHITE);
  15. // Pz = (-4.5 * t * t* t + 9*t*t - 5.5 *t +1)*P0z + (13.5 * t*t*t - 22.5 *t*t +9*t)*P1z + (-13.5 * t*t*t + 18*t*t -4.5*t)*P2z +(4.5*t*t*t -4.5*t*t +t)*P3z;
  16. }
  17.  
  18. int main(){
  19. int gd = DETECT, gm;
  20. initgraph(&gd, &gm, "C:\TC\BGI");
  21.  
  22. float t = 0;
  23. float P0x = 71, P0y = 165, R0x = -12, R0y = 2, P1x = 210, P1y = 153, R1x = 108, R1y = 0, Px= 0, Py = 0, Pz = 0;
  24. while(t<1){
  25. calcP(P0x, P0y, R0x, R0y, P1x, P1y, R1x, R1y, Px, Py, t);
  26. t+=0.001;
  27. }
  28. /*
  29. t = 0;
  30. float P0x = 170, P0y = 250, P1x = 170, P1y = 200, P2x = 170, P2y = 150, P3x = 170, P3y = 100, Px= 0, Py = 0, Pz = 0;
  31. while(t<1){
  32. calcP(Px, Py, Pz, t);
  33. t+=0.001;
  34. putpixel(Px, Py, WHITE);
  35. }
  36.  
  37. t = 0;
  38. P0x = 100, P0y = 165, P1x = 95, P1y = 180, P2x = 85, P2y = 180, P3x = 80, P3y = 165, Px= 0, Py = 0, Pz = 0;
  39. while(t<1){
  40. calcP(Px, Py, Pz, t);
  41. t+=0.001;
  42. putpixel(Px, Py, WHITE);
  43. }
  44. /*
  45. t = 0;
  46. P0x = 80, P0y = 165, P1x = 120, P1y = 165, P2x = 140, P2y = 165, P3x = 170, P3y = 165, Px= 0, Py = 0, Pz = 0;
  47. while(t<1){
  48. calcP(Px, Py, Pz, t);
  49. t+=0.001;
  50. putpixel(Px, Py, WHITE);
  51. }
  52.  
  53. t = 0;
  54. P0x = 80, P0y = 165, P1x = 120, P1y = 165, P2x = 140, P2y = 165, P3x = 160, P3y = 165, Px= 0, Py = 0, Pz = 0;
  55. while(t<1){
  56. calcP(Px, Py, Pz, t);
  57. t+=0.001;
  58. putpixel(Px, Py, WHITE);
  59. }
  60.  
  61. t = 0;
  62. P0x = 40, P0y = 100, P1x = 30, P1y = 70, P2x = 50, P2y = 45, P3x = 80, P3y = 50, Px= 0, Py = 0, Pz = 0;
  63. while(t<1){
  64. calcP(Px, Py, Pz, t);
  65. t+=0.001;
  66. putpixel(Px, Py, WHITE);
  67. }*/
  68. getch();
  69. closegraph();
  70. return 0;
  71. }
Add Comment
Please, Sign In to add comment