Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- #include <vector>
- #include <set>
- struct Point {
- double x;
- double y;
- } points;
- Point max(Point p1, Point p2) {
- if (p1.x > p2.x) return p1;
- else if (p1.x == p2.x) {
- if (p1.y > p2.y) return p1;
- }
- return p2;
- }
- Point min(Point p1, Point p2) {
- if (p1.x < p2.x) return p1;
- else if (p1.x == p2.x) {
- if (p1.y < p2.y) return p1;
- }
- return p2;
- }
- int main() {
- Point p1, p2, p3, l, r, start, finish;
- std::set<std::pair<double, double >> vPoint;
- int indX = 0, i = 0;
- std::cout << "enter start, end and reference point" << std::endl;
- std::cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
- vPoint.insert(std::make_pair(p1.x, p1.y));
- vPoint.insert(std::make_pair(p2.x, p2.y));
- r = max(p1, p2);
- l = min(p1, p2);
- finish = r;
- finish = max(finish, p3);
- start = l;
- start = min(start, p3);
- double t1 = 0, t2 = 0;
- for (indX = (int) start.x; indX <= finish.x; indX++) {
- i++;
- if ((l.x - 2 * p3.x + r.x) != 0) {
- t1 = (l.x - p3.x + sqrt((l.x - 2 * p3.x + r.x) * indX + pow(p3.x, 2) - l.x * r.x)) /
- (l.x - 2 * p3.x + r.x);
- t2 = (l.x - p3.x - sqrt((l.x - 2 * p3.x + r.x) * indX + pow(p3.x, 2) - l.x * r.x)) /
- (l.x - 2 * p3.x + r.x);
- } else if (((l.x - 2 * p3.x + r.x) == 0) && (l.x != p3.x))
- t1 = t2 = (indX - l.x) / (2 * (p3.x - l.x));
- else if ((l.x == p3.x) && (l.x != r.x)) {
- t1 = t2 = sqrt((indX - l.x) / (r.x - p3.x));
- }
- if(std::isnan(t1)) continue;
- if(std::isnan(t2)) continue;
- double y1 = pow(1 - t1, 2) * l.y + 2 * t1 * (1 - t1) * p3.y + pow(t1, 2) * r.y;
- double y2 = pow(1 - t2, 2) * l.y + 2 * t2 * (1 - t2) * p3.y + pow(t2, 2) * r.y;
- vPoint.insert(std::make_pair(indX, y1));
- if (t1 == t2) {
- i++;
- vPoint.insert(std::make_pair(indX, y2));
- }
- }
- for (auto i : vPoint) {
- int it = 0;
- std::cout << "Point №" << it++ << " X = " << i.first << " Y = " << i.second << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement