-
Notifications
You must be signed in to change notification settings - Fork 1
/
shape.h
173 lines (165 loc) · 4.21 KB
/
shape.h
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/******************************************************/
/* */
/* shape.h - shapes */
/* */
/******************************************************/
/* Copyright 2019-2021 Pierre Abbat.
* This file is part of Wolkenbase.
*
* Wolkenbase is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wolkenbase is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wolkenbase. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHAPE_H
#define SHAPE_H
#include "point.h"
class Cube
{
public:
Cube();
Cube(xyz c,double s);
bool in(xyz pnt);
xyz getCenter()
{
return center;
}
double getSide()
{
return side;
}
double minX()
{
return center.getx()-side/2;
}
double maxX()
{
return center.getx()+side/2;
}
double minY()
{
return center.gety()-side/2;
}
double maxY()
{
return center.gety()+side/2;
}
double minZ()
{
return center.getz()-side/2;
}
double maxZ()
{
return center.getz()+side/2;
}
xyz corner(int n);
private:
xyz center;
double side;
};
class Shape
{
public:
virtual bool in(xyz pnt) const=0;
virtual bool in(Cube &cube) const;
virtual xyz closestPoint(Cube cube) const=0; // closest point to the shape in the cube
virtual bool intersect(Cube cube) const;
};
class Paraboloid: public Shape
/* Points down if radiusCurvature is positive.
* radiusCurvature is the radius of curvature at the vertex,
* which is twice the focal length and half the latus rectum.
*/
{
public:
Paraboloid();
Paraboloid(xyz v,double r);
virtual bool in(xyz pnt) const;
virtual xyz closestPoint(Cube cube) const;
private:
xyz vertex;
double radiusCurvature;
};
class Hyperboloid: public Shape
/* One sheet of a two-sheet hyperboloid. Points down if slope is positive.
* The parameters are the vertex, the radius of curvature, and the slope.
* The members are the center, the polar radius squared, and the slope.
* The radius of curvature at the vertex (pole) of an ellipsoid is
* the square of the equatorial radius divided by the polar radius. The same
* formula holds for the hyperboloid, but as the equatorial radius is imaginary,
* the radius of curvature is negative, meaning that it is convex away from
* the center. This sign is ignored.
*/
{
public:
Hyperboloid();
Hyperboloid(xyz v,double r,double s);
virtual bool in(xyz pnt) const;
virtual xyz closestPoint(Cube cube) const;
private:
xyz center;
double por2,slope;
};
class Sphere: public Shape
/* Points down if radiusCurvature is positive.
* radiusCurvature is the radius of curvature at the vertex,
* which is twice the focal length and half the latus rectum.
*/
{
public:
Sphere();
Sphere(xyz c,double r);
virtual bool in(xyz pnt) const;
virtual xyz closestPoint(Cube cube) const;
private:
xyz center;
double radius;
};
class Cylinder: public Shape
/* Used for traversing the point cloud in flowsnake order.
* A hexagon in the lattice has a diapothem, which is also the distance to
* the adjacent hexagons. Construct a cylinder whose radius is 41/71 times
* the diapothem. This provides a tiny overlap at the corners so that
* no points are missed.
*/
{
public:
Cylinder();
Cylinder(xy c,double r);
double getRadius()
{
return radius;
}
xy getCenter()
{
return center;
}
virtual bool in(xyz pnt) const;
virtual xyz closestPoint(Cube cube) const;
private:
xy center;
double radius;
};
class Column: public Shape
/* Represents a pixel in the GUI.
* An infinitely tall prism with a square cross section.
*/
{
public:
Column();
Column(xy c,double s);
virtual bool in(xyz pnt) const;
virtual xyz closestPoint(Cube cube) const;
private:
xy center;
double side;
};
#endif