• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Apr 24th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. void Cyrus_Beck() {
2.     double t0 = 0;
3.     double t1 = 1;
4.     Point D = {points_line.x - points_line.x, points_line.y - points_line.y};
5.     points.push_back(points);
6.     for (int i = 0; i < points.size() - 1; i++) {
7.         Point ni = {points[i].y - points[i+1].y, points[i + 1].x - points[i].x};
8.         Point Wi = {points_line.x - points[i].x, points_line.y - points[i].y};
9.         double d = (ni.x * D.x) + (ni.y * D.y);
10.         double w = (Wi.x * ni.x) + (Wi.y * ni.y);
11.
12.         if (d == 0) {
13.             if (w < 0) {
14.                 continue;
15.             }
16.             continue;
17.         }
18.         double t = -w / d;
19.         if (d > 0) {
20.             if (t > 1) {
21.                 continue;
22.             }
23.             t0 = max(t, t0);
24.             continue;
25.         }
26.
27.         if (t < 0) {
28.             continue;
29.         }
30.         t1 = min(t, t1);
31.     }
32.     points.pop_back();
33.
34.     //cout << t0 << " " << t1 << endl;
35.
36.     Point p1 = {points_line.x + (points_line.x - points_line.x) * t0,
37.                 points_line.y + (points_line.y - points_line.y) * t0};
38.     Point p2 = {points_line.x + (points_line.x - points_line.x) * t1,
39.                 points_line.y + (points_line.y - points_line.y) * t1};
40.
41.     points_line = p1;
42.     points_line = p2;
43.    // cout << p1.x << " " << p1.y << endl;
44.     //cout << p2.x << " " << p2.y << endl;
45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top