Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- class Point {
- private:
- double x;
- double y;
- public:
- Point() {
- x = 0;
- y = 0;
- }
- Point(double _x, double _y) {
- x = _x;
- y = _y;
- }
- Point(const Point&b) {
- x = b.x;
- y = b.y;
- }
- Point operator+(const Point& p2)const
- {
- Point R;
- R.x = x + p2.x;
- R.y = y + p2.y;
- return R;
- }
- Point& operator+=(const Point& p2)
- {
- x = x + p2.x;
- y = y + p2.y;
- return *this;
- }
- Point operator*(const Point& b) const {
- Point P;
- P.x = x * b.x;
- P.y = y * b.y;
- return P;
- }
- Point operator*(double t) {
- Point P;
- P.x = x * t;
- P.y = y * t;
- return P;
- }
- friend Point operator*(const Point& P, double b) {
- Point R;
- R.x = P.x*b;
- R.y = P.y*b;
- return R;
- }
- friend double distance(const Point&A, const Point&B) {
- return sqrt((B.x - A.x)*(B.x - A.x) + (B.y - A.y)*(B.y - A.y));
- }
- };
- class Curve {
- public:
- Curve() {};
- ~Curve() {};
- virtual Point fun(int t) const = 0;
- double lenght(double t1, double t0) {
- double len = 0;
- double dt = (t1 - t0) / 100;
- for (int i = 0; i < 100;i++) {
- Point A = fun(t0+i*dt);
- Point B = fun(t0+(i-1)*dt);
- len += distance(A,B);
- }
- return len;
- }
- };
- class Polynome: public Curve {
- private:
- Point P1;
- Point P2;
- Point P3;
- public:
- Polynome(Point newP1, Point newP2, Point newP3) {
- P1 = newP1;
- P2 = newP2;
- P3 = newP3;
- }
- Polynome(double _x1, double _y1, double _x2, double _y2, double _x3, double _y3): P1(_x1,_y1), P2(_x2, _y2),
- P3(_x3, _y3) {};
- virtual Point fun(int t) const {
- Point F = P1 * t*t + P2*t + P3;
- return F;
- }
- using Curve::lenght;
- };
- int main()
- {
- Point nP1(0, 1);
- Point nP2(1, 0);
- Point nP3(0, 0);
- Polynome P(nP1, nP2, nP3);
- cout<<P.lenght(0, 1)<<endl;
- Polynome P1(0, 1, 1, 0, 0, 0);
- cout << P1.lenght(0, 1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement