-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe12.cpp
72 lines (59 loc) · 1.16 KB
/
e12.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Created by martin on 20/01/2022.
//
#include "Simple_window.h"
#include "Graph.h"
using namespace std;
using namespace Graph_lib;
int sgn (double d)
{
if (d < 0)
{
return -1;
}
else if (d > 0)
{
return 1;
}
return 0;
}
vector<Point> super_ellipse (double a, double b, double m, double n)
{
int xCenter = x_max() / 2;
int yCenter = y_max() / 2;
double precision = 0.01;
vector<Point> points;
Point temp;
Point point;
for (double d = -1.0 ; d < 1.0 ;)
{
double t = d * std::numbers::pi;
int x = int(a * pow(abs(cos(t)), 2.0 / m) * sgn(cos(t)));
int y = int(b * pow(abs(sin(t)), 2.0 / n) * sgn(sin(t)));
point = Point {x + xCenter, y + yCenter};
if (temp != point) // Check for duplicates
{
points.push_back(point);
}
temp = point;
d += precision;
}
return points;
}
int main ()
try
{
Simple_window win(Point {0, 0}, x_max(), y_max(), "Super-ellipse");
Graph_lib::Open_polyline op;
vector<Point> points = super_ellipse(300, 300, 0.5, 2.5);
for (Point p : points)
{
op.add(p);
}
win.attach(op);
win.wait_for_button();
}
catch (exception &e)
{
cerr << "Error: " << e.what() << endl;
}