![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include "LineSegment.hpp" 00029 #include "Vector.hpp" 00030 00031 using namespace wns::geometry; 00032 00033 //Constructors 00034 LineSegment::LineSegment() 00035 : Shape2D() 00036 {} 00037 00038 LineSegment::LineSegment(const Point& a, const Point& b) 00039 : Shape2D(a,b) 00040 { 00041 boundingBox = AABoundingBox(a, b); 00042 } 00043 00044 LineSegment::LineSegment(const Point& a, const Vector& db) 00045 : Shape2D(a, a + db) 00046 { 00047 boundingBox = AABoundingBox(a, a + db); 00048 } 00049 00050 LineSegment::LineSegment(const wns::pyconfig::View& config) 00051 : Shape2D(wns::geometry::Point(config.getView("pointA")), 00052 wns::geometry::Point(config.getView("pointB"))) 00053 { 00054 boundingBox = AABoundingBox(wns::geometry::Point(config.getView("pointA")), 00055 wns::geometry::Point(config.getView("pointB"))); 00056 } 00057 00058 LineSegment::~LineSegment() 00059 {} 00060 00061 00062 bool 00063 LineSegment::contains(const Point& point) const 00064 { 00065 return crossProduct(point) == 0.0 00066 && boundingBox.contains(point); 00067 } 00068 00069 00070 bool 00071 LineSegment::leftOf(const Point& point) const 00072 { 00073 return crossProduct(point) > 0.0; 00074 } 00075 00076 bool 00077 LineSegment::rightOf(const Point& point) const 00078 { 00079 return crossProduct(point) < 0.0; 00080 } 00081 00082 //LineSegment contains one endpoint of other 00083 bool 00084 LineSegment::touches(const LineSegment& other) const 00085 { 00086 return contains(other.a) != contains(other.b) 00087 && (crossProduct(other.a) != 0.0 00088 || crossProduct(other.b) != 0.0); 00089 } 00090 00091 00092 bool 00093 LineSegment::intersects(const LineSegment& that) const 00094 { 00095 return intersectsBoundingBoxOf(that) 00096 && ( (this->straddles(that) 00097 && that.straddles(*this)) 00098 ||(this->touches(that) 00099 || that.touches(*this))); 00100 } 00101 00102 unsigned int 00103 LineSegment::countBorderIntersections(const LineSegment& line) const 00104 { 00105 return intersects(line) ? 1 : 0; 00106 } 00107 00108 double 00109 LineSegment::crossProduct(const Point& x) const 00110 { 00111 return (b - a).cross(x - a).getDeltaZ(); 00112 } 00113 00114 bool 00115 LineSegment::straddles(const LineSegment& other) const 00116 { 00117 return (other.leftOf(a) == other.rightOf(b)); 00118 } 00119 00120 00121
1.5.5