00001
00002
00003
00004
00005
00006 #ifndef GEOMETRY_H
00007 #define GEOMETRY_H
00008
00009 #include<Vertex3.h>
00010
00013 namespace Geo
00014 {};
00015
00016
00017 inline real linear(real x)
00018 {
00019 return 1.0 - x;
00020 }
00021 inline real scurve(real x)
00022 {
00023 return x*x*(2.0*x-3.0) + 1.0;
00024 }
00025
00026
00027 inline real distanceToPlane(
00028 const Vertex3 &p, const Vertex3 &n, const Vertex3 &v)
00029 {
00030 return (v-p)*n;
00031 }
00032 inline real projectOnPlane(
00033 const Vertex3 &p, const Vertex3 &n, const Vertex3 &v, Vertex3 &vv)
00034 {
00035 real d = (v-p)*n;
00036 vv = v - n*d;
00037 return d;
00038 }
00039 inline float intersectPlane(
00040 const Vertex3 &p, const Vertex3 &n, const Vertex3 &o, const Vertex3 &d)
00041 {
00042 real dn = d*n;
00043 if (fabs(dn) > ZERO) {
00044 return (p - o)*n / dn;
00045 } else {
00046 return -1.0;
00047 }
00048 }
00049 inline float intersectSphere(
00050 const Vertex3 &p, float r, const Vertex3 &o, const Vertex3 &d)
00051 {
00052 Vertex3 Q = p - o;
00053 real c = Q.norm();
00054 real v = Q * d;
00055 real t = r*r - (c*c - v*v);
00056
00057 if (t < 0.0) {
00058 return -1.0;
00059 }
00060
00061 return v - sqrt(t);
00062 }
00063
00064
00065 bool pointInConvexPoly(
00066 const Vertex3 *v, const unsigned short *f,
00067 int N, const Vertex3 &p, const Vertex3 &n);
00068
00069 void closestPointOnLine(
00070 const Vertex3 &a, const Vertex3 &b, const Vertex3 &p,
00071 Vertex3 &closestPoint);
00072 Vertex3 closestPointOnPoly(
00073 const Vertex3 *v, const unsigned short *f, int N, const Vertex3 &p);
00074
00075
00076 real solveQuadric(real a, real b, real c);
00077 real distanceToBezierSeg(Vertex3 *bezier, Vertex3 &v);
00078
00079 #endif