00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _CELMATH_DISTANCE_H_
00013 #define _CELMATH_DISTANCE_H_
00014
00015 #include "mathlib.h"
00016 #include "ray.h"
00017 #include "sphere.h"
00018 #include "ellipsoid.h"
00019
00020
00021 template<class T> T distance(const Point3<T>& p, const Sphere<T>& s)
00022 {
00023 return abs(s.center.distanceTo(p) - s.radius);
00024 }
00025
00026 template<class T> T distance(const Point3<T>& p, const Ellipsoid<T>& e)
00027 {
00028 return 0.0f;
00029 }
00030
00031 template<class T> T distance(const Point3<T>& p, const Ray3<T>& r)
00032 {
00033 T t = ((p - r.origin) * r.direction) / (r.direction * r.direction);
00034 if (t <= 0)
00035 return p.distanceTo(r.origin);
00036 else
00037 return p.distanceTo(r.point(t));
00038 }
00039
00040 #endif // _CELMATH_DISTANCE_H_