Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

distance.h

Go to the documentation of this file.
00001 // distance.h
00002 //
00003 // Copyright (C) 2002, Chris Laurel <claurel@shatters.net>
00004 //
00005 // Distance calculation for various geometric objects.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
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_

Generated on Sat Jan 14 22:30:32 2006 for Celestia by  doxygen 1.4.1