# source:cpp/frams/model/geometry/geometryutils.h@193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

• Property svn:eol-style set to `native`
File size: 5.3 KB
Line
1// This file is a part of the Framsticks GDK.
2// Copyright (C) 2002-2014  Maciej Komosinski and Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#ifndef _GEOMETRYUTILS_H_
6#define _GEOMETRYUTILS_H_
7
8#include <frams/model/model.h>
9#include <frams/model/modelparts.h>
10#include <frams/util/3d.h>
11#include <frams/util/list.h>
12
13namespace CuboidFaces
14{
15        enum Face
16        {
17                NEGATIVE_X = 0,
18                POSITIVE_X = 1,
19                NEGATIVE_Y = 2,
20                POSITIVE_Y = 3,
21                NEGATIVE_Z = 4,
22                POSITIVE_Z = 5,
23                FIRST = 0,
24                NUMBER = 6
25        };
26
27        inline bool isPositive(Face f) { return f & 0b001; }
28        inline bool isNegative(Face f) { return !isPositive(f); }
29        inline bool isX(Face f) { return (f & 0b110) == 0b000; }
30        inline bool isY(Face f) { return (f & 0b110) == 0b010; }
31        inline bool isZ(Face f) { return (f & 0b110) == 0b100; }
32}
33
34namespace CylinderBases
35{
36        enum Base
37        {
38                NEGATIVE_X = 0,
39                POSITIVE_X = 1,
40                FIRST = 0,
41                NUMBER = 2
42        };
43
44        inline bool isPositive(Base b) { return b & 0b001; }
45        inline bool isNegative(Base b) { return !isPositive(b); }
46}
47
49{
51        {
52                NEGATIVE_X_NEGATIVE_Y = 0,
53                NEGATIVE_X_POSITIVE_Y = 1,
54                POSITIVE_X_NEGATIVE_Y = 2,
55                POSITIVE_X_POSITIVE_Y = 3,
56                FIRST = 0,
57                NUMBER = 4
58        };
59
60        inline bool isPositiveX(QuadrantXY q) { return q & 0b10; }
61        inline bool isNegativeX(QuadrantXY q) { return !isPositiveX(q); }
62        inline bool isPositiveY(QuadrantXY q) { return q & 0b01; }
63        inline bool isNegativeY(QuadrantXY q) { return !isPositiveY(q); }
64}
65
67{
69        {
70                NEGATIVE_Y_NEGATIVE_Z = 0,
71                NEGATIVE_Y_POSITIVE_Z = 1,
72                POSITIVE_Y_NEGATIVE_Z = 2,
73                POSITIVE_Y_POSITIVE_Z = 3,
74                FIRST = 0,
75                NUMBER = 4
76        };
77
78        inline bool isPositiveY(QuadrantYZ q) { return q & 0b10; }
79        inline bool isNegativeY(QuadrantYZ q) { return !isPositiveY(q); }
80        inline bool isPositiveZ(QuadrantYZ q) { return q & 0b01; }
81        inline bool isNegativeZ(QuadrantYZ q) { return !isPositiveZ(q); }
82}
83
85{
87        {
88                NEGATIVE_Z_NEGATIVE_X = 0,
89                NEGATIVE_Z_POSITIVE_X = 1,
90                POSITIVE_Z_NEGATIVE_X = 2,
91                POSITIVE_Z_POSITIVE_X = 3,
92                FIRST = 0,
93                NUMBER = 4
94        };
95
96        inline bool isPositiveZ(QuadrantZX q) { return q & 0b10; }
97        inline bool isNegativeZ(QuadrantZX q) { return !isPositiveZ(q); }
98        inline bool isPositiveX(QuadrantZX q) { return q & 0b01; }
99        inline bool isNegativeX(QuadrantZX q) { return !isPositiveX(q); }
100}
101
102namespace Octants
103{
104        enum Octant
105        {
106                NEGATIVE_X_NEGATIVE_Y_NEGATIVE_Z = 0,
107                NEGATIVE_X_NEGATIVE_Y_POSITIVE_Z = 1,
108                NEGATIVE_X_POSITIVE_Y_NEGATIVE_Z = 2,
109                NEGATIVE_X_POSITIVE_Y_POSITIVE_Z = 3,
110                POSITIVE_X_NEGATIVE_Y_NEGATIVE_Z = 4,
111                POSITIVE_X_NEGATIVE_Y_POSITIVE_Z = 5,
112                POSITIVE_X_POSITIVE_Y_NEGATIVE_Z = 6,
113                POSITIVE_X_POSITIVE_Y_POSITIVE_Z = 7,
114                FIRST = 0,
115                NUMBER = 8
116        };
117
118        inline bool isPositiveX(Octant o) { return o & 0b100; }
119        inline bool isNegativeX(Octant o) { return !isPositiveX(o); }
120        inline bool isPositiveY(Octant o) { return o & 0b010; }
121        inline bool isNegativeY(Octant o) { return !isPositiveY(o); }
122        inline bool isPositiveZ(Octant o) { return o & 0b001; }
123        inline bool isNegativeZ(Octant o) { return !isPositiveZ(o); }
124}
125
126namespace GeometryUtils
127{
128        double pointPosition(const int pointIndex, const int numberOfPoints);
129        double pointOnAxis(const double scale, const double position);
130        double pointOnAxis(const double scale, const int pointIndex, const int numberOfPoints);
131        double combination(const double value1, const double value2, const double position);
132        double combination(const double value1, const double value2, const int pointIndex, const int numberOfPoints);
133        bool isPointInsideModelExcludingPart(const Pt3D &point, const Model *model, const int excludedPartIndex);
134        bool isPointInsideModel(const Pt3D &point, const Model &model);
135        bool isPointInsidePart(const Pt3D &point, const Part *part);
136        bool isPointStrictlyInsidePart(const Pt3D &point, const Part *part);
137        bool isPointInsideEllipsoid(const Pt3D &point, const Part *part);
138        bool isPointStrictlyInsideEllipsoid(const Pt3D &point, const Part *part);
139        bool isPointInsideCuboid(const Pt3D &point, const Part *part);
140        bool isPointStrictlyInsideCuboid(const Pt3D &point, const Part *part);
141        bool isPointInsideCylinder(const Pt3D &point, const Part *part);
142        bool isPointStrictlyInsideCylinder(const Pt3D &point, const Part *part);
143        void findSizesAndAxesOfPointsGroup(SListTempl<Pt3D> &points, Pt3D &sizes, Orient &axes);
144        void findSizeAndAxisOfPointsGroup(const SListTempl<Pt3D> &points, double &size, Pt3D &axis);
145        double findTwoFurthestPoints(const SListTempl<Pt3D> &points, int &index1, int &index2);
146        void createAxisFromTwoPoints(Pt3D &axis, const Pt3D &point1, const Pt3D &point2);
147        void orthographicProjectionToPlane(SListTempl<Pt3D> &points, const Pt3D &planeNormalVector);
148        double pointDistanceToPlane(const Pt3D &point, const Pt3D &planeNormalVector);
149        void getRectangleApicesFromCuboid(const Part *part, const CuboidFaces::Face face, Pt3D &apex1, Pt3D &apex2, Pt3D &apex3, Pt3D &apex4);
150        void getRectangleApices(const double width, const double height, const Pt3D &position, const Orient &orient, Pt3D &apex1, Pt3D &apex2, Pt3D &apex3, Pt3D &apex4);
151        void getNextEllipseSegmentationPoint(const double d, const double a, const double b, double &x, double &y);
152        double ellipsoidArea(const Pt3D &sizes);
153        double ellipsoidArea(const double a, const double b, const double c);
154        double ellipsePerimeter(const double a, const double b);
155}
156
157#endif
Note: See TracBrowser for help on using the repository browser.