Advertisement
Guest User

mytona_5

a guest
Jan 26th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. #include <vector>
  5. #include <set>
  6.  
  7. struct Point {
  8.     double x;
  9.     double y;
  10. } points;
  11.  
  12. Point max(Point p1, Point p2) {
  13.     if (p1.x > p2.x) return p1;
  14.     else if (p1.x == p2.x) {
  15.         if (p1.y > p2.y) return p1;
  16.     }
  17.     return p2;
  18. }
  19.  
  20. Point min(Point p1, Point p2) {
  21.     if (p1.x < p2.x) return p1;
  22.     else if (p1.x == p2.x) {
  23.         if (p1.y < p2.y) return p1;
  24.     }
  25.     return p2;
  26. }
  27.  
  28. int main() {
  29.     Point p1, p2, p3, l, r, start, finish;
  30.     std::set<std::pair<double, double >> vPoint;
  31.     int indX = 0, i = 0;
  32.     std::cout << "enter start, end and reference point" << std::endl;
  33.     std::cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
  34.     vPoint.insert(std::make_pair(p1.x, p1.y));
  35.     vPoint.insert(std::make_pair(p2.x, p2.y));
  36.     r = max(p1, p2);
  37.     l = min(p1, p2);
  38.     finish = r;
  39.     finish = max(finish, p3);
  40.     start = l;
  41.     start = min(start, p3);
  42.     double t1 = 0, t2 = 0;
  43.     for (indX = (int) start.x; indX <= finish.x; indX++) {
  44.         i++;
  45.         if ((l.x - 2 * p3.x + r.x) != 0) {
  46.             t1 = (l.x - p3.x + sqrt((l.x - 2 * p3.x + r.x) * indX + pow(p3.x, 2) - l.x * r.x)) /
  47.                  (l.x - 2 * p3.x + r.x);
  48.             t2 = (l.x - p3.x - sqrt((l.x - 2 * p3.x + r.x) * indX + pow(p3.x, 2) - l.x * r.x)) /
  49.                  (l.x - 2 * p3.x + r.x);
  50.         } else if (((l.x - 2 * p3.x + r.x) == 0) && (l.x != p3.x))
  51.             t1 = t2 = (indX - l.x) / (2 * (p3.x - l.x));
  52.         else if ((l.x == p3.x) && (l.x != r.x)) {
  53.             t1 = t2 = sqrt((indX - l.x) / (r.x - p3.x));
  54.         }
  55.         if(std::isnan(t1)) continue;
  56.         if(std::isnan(t2)) continue;
  57.         double y1 = pow(1 - t1, 2) * l.y + 2 * t1 * (1 - t1) * p3.y + pow(t1, 2) * r.y;
  58.         double y2 = pow(1 - t2, 2) * l.y + 2 * t2 * (1 - t2) * p3.y + pow(t2, 2) * r.y;
  59.         vPoint.insert(std::make_pair(indX, y1));
  60.         if (t1 == t2) {
  61.             i++;
  62.             vPoint.insert(std::make_pair(indX, y2));
  63.         }
  64.     }
  65.     for (auto i : vPoint) {
  66.         int it = 0;
  67.         std::cout << "Point №" << it++ << " X = " << i.first << " Y = " << i.second << std::endl;
  68.     }
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement