00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ARCHON_MATH_GEOMETRY_H
00021 #define ARCHON_MATH_GEOMETRY_H
00022
00023 #include <archon/math/vector.H>
00024 #include <archon/math/matrix.H>
00025
00026 namespace Archon
00027 {
00028 namespace Math
00029 {
00030 struct Line3
00031 {
00032 Vector3 point;
00033 Vector3 direction;
00034
00035 Line3() {}
00036 Line3(Vector3 point, Vector3 direction): point(point), direction(direction) {}
00037 };
00038
00046 struct Plane3
00047 {
00054 Vector3 normal;
00055
00061 double dist;
00062
00063 Plane3() {}
00064 Plane3(Vector3 normal, double dist): normal(normal), dist(dist) {}
00065 Plane3(Vector3 normal, Vector3 point): normal(normal), dist(-dot(normal, point)) {}
00066 };
00067
00068 Vector3 intersect(const Plane3 &, const Plane3 &, const Plane3 &);
00069
00070 struct Ray3
00071 {
00072 Vector3 origin;
00073 Vector3 direction;
00074
00075 Ray3() {}
00076 Ray3(const Vector3 &origin, const Vector3 &direction):
00077 origin(origin), direction(direction) {}
00078 Ray3(const Line3 &l): origin(l.point), direction(l.direction) {}
00079 };
00080
00084 struct Box3
00085 {
00086 Vector3 lowerCorner;
00087 Vector3 upperCorner;
00088
00089 Box3() {}
00090 Box3(const Vector3 &lowerCorner, const Vector3 &upperCorner):
00091 lowerCorner(lowerCorner), upperCorner(upperCorner) {}
00092 Box3(const Vector3 &size):
00093 lowerCorner(-size/2), upperCorner(size/2) {}
00094
00095 Vector3 getCenter() const { return (lowerCorner + upperCorner)/2; }
00096 Vector3 getSize() const
00097 {
00098 Vector3 v = lowerCorner;
00099 v -= upperCorner;
00100 if(v[0] < 0) v[0] = -v[0];
00101 if(v[1] < 0) v[1] = -v[1];
00102 if(v[2] < 0) v[2] = -v[2];
00103 return v;
00104 }
00105 };
00106
00107 struct Sphere3
00108 {
00109 Vector3 center;
00110 double radius;
00111
00112 Sphere3() {}
00113 Sphere3(Vector3 center, double radius):
00114 center(center), radius(radius) {}
00115 Sphere3(double radius):
00116 center(Vector3::zero()), radius(radius) {}
00117 };
00118
00135 bool intersect(const Ray3 &, const Plane3 &, bool frontToBackOnly, double &dist);
00136
00163 int intersect(const Ray3 &, const Box3 &, double &dist);
00164
00185 bool intersect(const Ray3 &, const Sphere3 &, double &dist);
00186
00312 int intersectCylinder(const Ray3 &, double height, double radius,
00313 double &dist, bool side=true, bool top=true,
00314 bool bottom=true, bool enterOnly = true);
00315
00589 int intersectCone(const Ray3 &, double height, double bottomRadius,
00590 double &dist, bool side=true, bool bottom=true,
00591 bool enterOnly = true);
00592
00616 bool intersectTorus(const Ray3 &, double majorTorusRadius,
00617 double minorTorusRadius, double &dist,
00618 bool surfaceOrigin = false, bool extToIntOnly = true);
00619 }
00620 }
00621
00622 #endif // ARCHON_MATH_GEOMETRY_H