Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Point {
  6. private:
  7. double x;
  8. double y;
  9. public:
  10. Point() {
  11. x = 0;
  12. y = 0;
  13. }
  14. Point(double _x, double _y) {
  15. x = _x;
  16. y = _y;
  17. }
  18. Point(const Point&b) {
  19. x = b.x;
  20. y = b.y;
  21. }
  22.  
  23. Point operator+(const Point& p2)const
  24. {
  25. Point R;
  26. R.x = x + p2.x;
  27. R.y = y + p2.y;
  28. return R;
  29.  
  30. }
  31. Point& operator+=(const Point& p2)
  32. {
  33. x = x + p2.x;
  34. y = y + p2.y;
  35. return *this;
  36.  
  37. }
  38.  
  39. Point operator*(const Point& b) const {
  40. Point P;
  41. P.x = x * b.x;
  42. P.y = y * b.y;
  43. return P;
  44. }
  45. Point operator*(double t) {
  46.  
  47. Point P;
  48. P.x = x * t;
  49. P.y = y * t;
  50. return P;
  51. }
  52. friend Point operator*(const Point& P, double b) {
  53. Point R;
  54. R.x = P.x*b;
  55. R.y = P.y*b;
  56. return R;
  57. }
  58. friend double distance(const Point&A, const Point&B) {
  59. return sqrt((B.x - A.x)*(B.x - A.x) + (B.y - A.y)*(B.y - A.y));
  60. }
  61. };
  62.  
  63. class Curve {
  64. public:
  65. Curve() {};
  66. ~Curve() {};
  67. virtual Point fun(int t) const = 0;
  68. double lenght(double t1, double t0) {
  69. double len = 0;
  70. double dt = (t1 - t0) / 100;
  71.  
  72. for (int i = 0; i < 100;i++) {
  73.  
  74. Point A = fun(t0+i*dt);
  75. Point B = fun(t0+(i-1)*dt);
  76. len += distance(A,B);
  77.  
  78. }
  79. return len;
  80. }
  81.  
  82. };
  83.  
  84. class Polynome: public Curve {
  85. private:
  86. Point P1;
  87. Point P2;
  88. Point P3;
  89. public:
  90. Polynome(Point newP1, Point newP2, Point newP3) {
  91. P1 = newP1;
  92. P2 = newP2;
  93. P3 = newP3;
  94. }
  95. Polynome(double _x1, double _y1, double _x2, double _y2, double _x3, double _y3): P1(_x1,_y1), P2(_x2, _y2),
  96. P3(_x3, _y3) {};
  97.  
  98. virtual Point fun(int t) const {
  99. Point F = P1 * t*t + P2*t + P3;
  100. return F;
  101. }
  102.  
  103. using Curve::lenght;
  104.  
  105. };
  106.  
  107.  
  108.  
  109. int main()
  110. {
  111. Point nP1(0, 1);
  112. Point nP2(1, 0);
  113. Point nP3(0, 0);
  114. Polynome P(nP1, nP2, nP3);
  115. cout<<P.lenght(0, 1)<<endl;
  116. Polynome P1(0, 1, 1, 0, 0, 0);
  117. cout << P1.lenght(0, 1);
  118.  
  119.  
  120.  
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement