Simbody  3.4 (development)
Geo_LineSeg.h
Go to the documentation of this file.
00001 #ifndef SimTK_SIMMATH_GEO_LINESEG_H_
00002 #define SimTK_SIMMATH_GEO_LINESEG_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                        Simbody(tm): SimTKmath                              *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2011-12 Stanford University and the Authors.        *
00013  * Authors: Michael Sherman                                                   *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00030 #include "SimTKcommon.h"
00031 #include "simmath/internal/common.h"
00032 #include "simmath/internal/Geo.h"
00033 #include "simmath/internal/Geo_Sphere.h"
00034 
00035 #include <cassert>
00036 #include <cmath>
00037 #include <algorithm>
00038 
00039 namespace SimTK {
00040 
00041 
00042 //==============================================================================
00043 //                               GEO LINESEG
00044 //==============================================================================
00049 template <class P>
00050 class SimTK_SIMMATH_EXPORT Geo::LineSeg_ {
00051 typedef P               RealP;
00052 typedef Vec<3,RealP>    Vec3P;
00053 
00054 public:
00057 LineSeg_() {}
00058 
00061 LineSeg_(const Vec3P& e0, const Vec3P& e1) 
00062 {   setEndpoints(e0,e1); }
00063 
00065 LineSeg_& setEndpoints(const Vec3P& e0, const Vec3P& e1) 
00066 {   e[0]=e0; e[1]=e1; return *this; }
00067 
00069 LineSeg_& setEndpoint(int which, const Vec3P& p)
00070 {   assert(which==0 || which==1); e[which] = p; return *this; }
00071 
00077 bool isDegenerate(RealP tol = Geo::getDefaultTol<P>()) const
00078 {   assert(tol >= 0); return calcLengthSqr() <= square(tol); }
00079 
00082 const Vec3P& getEndpoint(int which) const 
00083 {   assert(which==0 || which==1); return e[which]; }
00084 
00088 Vec3P& updEndpoint(int which) 
00089 {   assert(which==0 || which==1); return e[which]; }
00090 
00092 const Vec3P& operator[](int which) const {return getEndpoint(which);}
00094 Vec3P& operator[](int which) {return updEndpoint(which);}
00095 
00098 RealP calcLength() const {return (e[1]-e[0]).norm(); }
00099 
00102 RealP calcLengthSqr() const {return (e[1]-e[0]).normSqr(); }
00103 
00108 Vec3P findPoint(RealP t) const
00109 {   return t*e[0] + (1-t)*e[1]; }
00110 
00113 Vec3P findMidpoint() const
00114 {   return (e[0]+e[1]) / RealP(2); }
00115 
00119 Sphere_<P> calcBoundingSphere() const 
00120 {   return Geo::Point_<P>::calcBoundingSphere(e[0],e[1]); }
00121 
00124 RealP findDistanceToPoint(const Vec3P& p2) const
00125 {SimTK_ASSERT_ALWAYS(!"implemented", 
00126 "Geo::LineSeg_::findDistanceToPoint(): Not implemented yet.");
00127 return Geo::getNaN<P>();}
00128 
00131 RealP findDistanceToPointSqr(const Vec3P& p2) const
00132 {SimTK_ASSERT_ALWAYS(!"implemented", 
00133 "Geo::LineSeg_::findDistanceToPointSqr(): Not implemented yet.");
00134 return Geo::getNaN<P>();}
00135 
00142 private:
00143 Vec3P   e[2];
00144 };
00145 
00146 
00147 } // namespace SimTK
00148 
00149 #endif // SimTK_SIMMATH_GEO_LINESEG_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines