Changeset 74:933f1acf1484 in rrlib_geometry


Ignore:
Timestamp:
26.05.2016 10:28:43 (3 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
14.08
Children:
75:62e144a61a60, 76:e6f537899176
Phase:
public
Message:

Adds detection of infinite intersection points for lines

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tLine.h

    r60 r74  
    6464// Forward declarations / typedefs / enums 
    6565//---------------------------------------------------------------------- 
     66enum tIntersectionType 
     67{ 
     68  NONE, 
     69  SINGLE, 
     70  INFINITE 
     71}; 
    6672 
    6773//---------------------------------------------------------------------- 
     
    107113  virtual const typename tShape::tPoint GetClosestPoint(const typename tShape::tPoint &reference_point) const; 
    108114 
    109   const bool GetIntersection(typename tShape::tPoint &intersection_point, const tLine &line) const; 
     115  tIntersectionType GetIntersection(typename tShape::tPoint &intersection_point, const tLine &line) const; 
    110116 
    111117  virtual tLine &Translate(const math::tVector<Tdimension, TElement> &translation); 
  • tLine.hpp

    r60 r74  
    134134 
    135135template <size_t Tdimension, typename TElement> 
    136 bool IntersectLineWithLine(typename tLine<Tdimension, TElement>::tPoint &intersection_point, const tLine<Tdimension, TElement> &left, const tLine<Tdimension, TElement> &right) 
    137 { 
     136tIntersectionType IntersectLineWithLine(typename tLine<Tdimension, TElement>::tPoint &intersection_point, const tLine<Tdimension, TElement> &left, const tLine<Tdimension, TElement> &right) 
     137{ 
     138  if (left.Direction() == right.Direction() || left.Direction() == -right.Direction()) 
     139  { 
     140    if (left.GetClosestPoint(right.Support()) == right.Support()) 
     141    { 
     142      intersection_point = right.Support(); 
     143      return tIntersectionType::INFINITE; 
     144    } 
     145    return tIntersectionType::NONE; 
     146  } 
     147 
    138148  math::tMatrix<Tdimension, 2, TElement> matrix; 
    139149  for (size_t i = 0; i < Tdimension; ++i) 
     
    147157    TElement t = math::tLUDecomposition<2, TElement>(matrix).Solve(right.Support() - left.Support())[0]; 
    148158    intersection_point = left.Support() + t * left.Direction(); 
    149     return true; 
     159    return tIntersectionType::SINGLE; 
    150160  } 
    151161  catch (const std::logic_error &) 
    152162  { 
    153     return false; 
    154   } 
    155 } 
    156  
    157 template <size_t Tdimension, typename TElement> 
    158 bool IntersectLineWithLineSegment(typename tLine<Tdimension, TElement>::tPoint &intersection_point, const tLine<Tdimension, TElement> &left, const geometry::tLineSegment<Tdimension, TElement> &right) 
     163    return tIntersectionType::NONE; 
     164  } 
     165} 
     166 
     167template <size_t Tdimension, typename TElement> 
     168tIntersectionType IntersectLineWithLineSegment(typename tLine<Tdimension, TElement>::tPoint &intersection_point, const tLine<Tdimension, TElement> &left, const geometry::tLineSegment<Tdimension, TElement> &right) 
    159169{ 
    160170  if (!IntersectLineWithLine(intersection_point, left, right)) 
    161171  { 
    162     return false; 
    163   } 
    164   return math::IsEqual(right.GetDistanceToPoint(intersection_point), 0); 
    165 } 
    166  
    167 template <size_t Tdimension, typename TElement> 
    168 bool IntersectLineSegmentWithLineSegment(typename tLine<Tdimension, TElement>::tPoint &intersection_point, const tLineSegment<Tdimension, TElement> &left, const tLineSegment<Tdimension, TElement> &right) 
     172    return tIntersectionType::NONE; 
     173  } 
     174  return math::IsEqual(right.GetDistanceToPoint(intersection_point), 0) ? tIntersectionType::SINGLE : tIntersectionType::NONE; 
     175} 
     176 
     177template <size_t Tdimension, typename TElement> 
     178tIntersectionType IntersectLineSegmentWithLineSegment(typename tLine<Tdimension, TElement>::tPoint &intersection_point, const tLineSegment<Tdimension, TElement> &left, const tLineSegment<Tdimension, TElement> &right) 
    169179{ 
    170180  if (!left.BoundingBox().Intersects(right.BoundingBox())) 
    171181  { 
    172     return false; 
     182    return tIntersectionType::NONE; 
    173183  } 
    174184 
    175185  if (!IntersectLineWithLineSegment(intersection_point, left, right)) 
    176186  { 
    177     return false; 
    178   } 
    179   return math::IsEqual(left.GetDistanceToPoint(intersection_point), 0); 
     187    return tIntersectionType::NONE; 
     188  } 
     189  return math::IsEqual(left.GetDistanceToPoint(intersection_point), 0) ? tIntersectionType::SINGLE : tIntersectionType::NONE; 
    180190} 
    181191 
     
    186196//---------------------------------------------------------------------- 
    187197template <size_t Tdimension, typename TElement> 
    188 const bool tLine<Tdimension, TElement>::GetIntersection(typename tShape::tPoint &intersection_point, const tLine &line) const 
     198tIntersectionType tLine<Tdimension, TElement>::GetIntersection(typename tShape::tPoint &intersection_point, const tLine &line) const 
    189199{ 
    190200  typedef geometry::tLineSegment<Tdimension, TElement> tLineSegment; 
Note: See TracChangeset for help on using the changeset viewer.