00001 /** 00002 * \file Segment3D.h 00003 * \brief simple implementation of segments in 3D 00004 * 00005 * Copyright 2007-2010 IMP Inventors. All rights reserved. 00006 */ 00007 #ifndef IMPALGEBRA_SEGMENT_3D_H 00008 #define IMPALGEBRA_SEGMENT_3D_H 00009 00010 #include "Vector3D.h" 00011 #include "BoundingBoxD.h" 00012 #include "algebra_macros.h" 00013 #include <iostream> 00014 #include <IMP/constants.h> 00015 00016 00017 IMPALGEBRA_BEGIN_NAMESPACE 00018 /** It does what is says. 00019 \geometry 00020 */ 00021 class IMPALGEBRAEXPORT Segment3D 00022 { 00023 public: 00024 Segment3D(){} 00025 Segment3D(const VectorD<3> &start,const VectorD<3> &end); 00026 //! Get the start=0/end=1 point of the segment 00027 const VectorD<3>& get_point(unsigned int i) const { 00028 #if IMP_SWIG_WRAPPER 00029 IMP_USAGE_CHECK(i<2,"invalid point index"); 00030 #else 00031 IMP_INTERNAL_CHECK(i<2, "Invalid point index"); 00032 #endif 00033 return p_[i]; 00034 } 00035 VectorD<3> get_middle_point() const { 00036 return .5*p_[0]+ .5*p_[1]; 00037 } 00038 /** \brief Get a normalized direction vector pointing from 00039 get_point(0) to get_point(1). 00040 */ 00041 VectorD<3> get_direction() const {return (p_[1]-p_[0]).get_unit_vector();} 00042 double get_length() const; 00043 IMP_SHOWABLE_INLINE({out << spaces_io(p_[0]) << ": " << spaces_io(p_[1]);}); 00044 private: 00045 VectorD<3> p_[2]; 00046 }; 00047 00048 IMP_LINEAR_GEOMETRY_METHODS(Segment3D, 00049 return BoundingBoxD<3>(g.get_point(0)) 00050 +BoundingBoxD<3>(g.get_point(1))); 00051 00052 00053 00054 //! Get the distance between a segment and a point 00055 /** \relatesalso Segment3D */ 00056 IMPALGEBRAEXPORT double get_distance(const Segment3D &s, const VectorD<3> &p); 00057 00058 //! Get the distance between two segments 00059 /** \relatesalso Segment3D */ 00060 IMPALGEBRAEXPORT double get_distance(const Segment3D &a, const Segment3D &b); 00061 00062 00063 IMPALGEBRA_END_NAMESPACE 00064 00065 #endif /* IMPALGEBRA_SEGMENT_3D_H */