CVR-Lib last update 20 Sep 2009

cvrGeometry.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998 - 2004
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 
00042 /**
00043  * \file   cvrGeometry.h
00044  *         Defines three line geometry related global functions:
00045  *         - intersection() computes the intersection point between two lines.
00046  *         - minDistanceSqr() computes the shortest square distance between
00047  *           a point and a line.
00048  *         - clockwiseTurn() indicates whether two lines form a clock-wise,
00049  *           anti clock-wise, or no turn.
00050  * \author Pablo Alvarado
00051  * \date   19.03.2002
00052  *
00053  * $Id: cvrGeometry.h,v 1.3 2005/01/03 16:17:51 alvarado Exp $
00054  */
00055 
00056 #ifndef _CVR_GEOMETRY_H_
00057 #define _CVR_GEOMETRY_H_
00058 
00059 #include "cvrMath.h"
00060 #include "cvrTypes.h"
00061 #include "cvrPoint.h"
00062 
00063 namespace cvr {
00064 
00065   /**
00066    * Line intersection.
00067    *
00068    * Compute if the line between p1 and p2 intersects with the line
00069    * between p3 and p4.  If they intersect in exactly one point
00070    * (normal case) the function returns true.  If the lines are
00071    * parallel or any of the lines have length 0 this function returns
00072    * false.
00073    *
00074    * @param p1 begin of first line
00075    * @param p2 end of first line
00076    * @param p3 begin of first line
00077    * @param p4 end of first line
00078    * @param p intersection point will be written here, in case there is one.
00079    *          if there is no intersection point (or infinity) the value
00080    *          will not change.
00081    *
00082    * @return true if lines intersect in exactly one point, false otherwise
00083    *
00084    * @ingroup gGeometry
00085    *
00086    * Defined in cvrGeometry.h
00087    */
00088   template<class T>
00089   bool intersection(const point<T>& p1,const point<T>& p2,
00090                     const point<T>& p3,const point<T>& p4,
00091                     point<T>& p);
00092 
00093   /**
00094    * Line intersection.
00095    *
00096    * Compute if the line between p1 and p2 intersects with the line
00097    * between p3 and p4.  If they intersect in exactly one point
00098    * (normal case) the function returns true.  If the lines are
00099    * parallel or any of the lines have length 0 this function returns
00100    * false.
00101    *
00102    * @param p1 begin of first line
00103    * @param p2 end of first line
00104    * @param p3 begin of first line
00105    * @param p4 end of first line
00106    *
00107    * @return true if lines intersect in exactly one point, false otherwise
00108    *
00109    * @ingroup gGeometry
00110    *
00111    * Defined in cvrGeometry.h
00112    */
00113   template<class T>
00114   inline bool intersection(const point<T>& p1,const point<T>& p2,
00115                            const point<T>& p3,const point<T>& p4) {
00116     point<T> p;
00117     return intersection(p1,p2,p3,p4,p);
00118   }
00119 
00120   /**
00121    * Distance between line segment and point.
00122    *
00123    * Compute the square of the minimal distance between the line
00124    * segment defined by the points p1 and p2 and the point p3.  The
00125    * point within the line with the minimal distance will be stored in
00126    * p.
00127    *
00128    * @param p1 start point of the line segment
00129    * @param p2 end point of the line segment
00130    * @param p3 point, for which the distance to the line segment will be
00131    *           computed.
00132    * @param p  the point in the line between p1 and p2 with the shortest
00133    *           distance will be stored here.
00134    * @return the square of the distance between the line p1_p2 and the point
00135    *         p3
00136    *
00137    * @ingroup gGeometry
00138    *
00139    * Defined in cvrGeometry.h
00140    */
00141   template<class T>
00142   T minDistanceSqr(const point<T>& p1,
00143                  const point<T>& p2,
00144                  const point<T>& p3,
00145                  point<T>& p);
00146 
00147   /**
00148    * Distance between line segment and point.
00149    *
00150    * Compute the square of the minimal distance between the line
00151    * segment defined by the points p1 and p2 and the point p3.  The
00152    * point within the line with the minimal distance will be stored in
00153    * p.
00154    *
00155    * @param p1 start point of the line segment
00156    * @param p2 end point of the line segment
00157    * @param p3 point, for which the distance to the line segment will be
00158    *           computed.
00159    * @return the square of the distance between the line p1_p2 and the point
00160    *         p3
00161    *
00162    * @ingroup gGeometry
00163    *
00164    * Defined in cvrGeometry.h
00165    */
00166   template<class T>
00167   inline T minDistanceSqr(const point<T>& p1,
00168                           const point<T>& p2,
00169                           const point<T>& p3) {
00170     point<T> tmp;
00171     return minDistanceSqr(p1,p2,p3,tmp);
00172   }
00173 
00174   /**
00175    * Distance between two line segments.
00176    *
00177    * Compute the square of the minimal distance between the line
00178    * segment defined by the points p1 and p2 and the line segment
00179    * defined by the points p3 and p4.  The corresponding points with the
00180    * minimal distance will be stored in pa (in p1-p2) and pb (in p3-p4).
00181    *
00182    * @param p1 start point of the first line segment
00183    * @param p2 end point of the first line segment
00184    * @param p3 start point of the second line segment
00185    * @param p4 end point of the second line segment
00186    * @param pa point in the line p1-p2 with the minimal distance to
00187    *           the line segment p3-p4.
00188    * @param pb point in the line p3-p4 with the minimal distance to
00189    *           the line segment p1-p2.
00190    * @return the square of the distance between the line p1-p2 and p3-p4
00191    *
00192    * @ingroup gGeometry
00193    *
00194    * Defined in cvrGeometry.h
00195    */
00196   template<class T>
00197   T minDistanceSqr(const point<T>& p1,
00198                    const point<T>& p2,
00199                    const point<T>& p3,
00200                    const point<T>& p4,
00201                    point<T>& pa,
00202                    point<T>& pb);
00203 
00204   /**
00205    * Turn orientation in a three-point path.
00206    *
00207    * Compute if the path that follows the points p0, p1 and p2
00208    * makes a clock-wise turn (+1) a counter-clock-wise turn (-1) or
00209    * stays in a straight line (0).
00210    *
00211    * @param p0 first point
00212    * @param p1 second point
00213    * @param p2 third point
00214    *
00215    * @return +1 for a clockwise turn, -1 for a counter clockwise turn, 0
00216    *         if path stays in a straight line.
00217    *
00218    * @ingroup gGeometry
00219    *
00220    * Defined in cvrGeometry.h
00221    */
00222   template<class T>
00223   int clockwiseTurn(const point<T>& p0,
00224                     const point<T>& p1,
00225                     const point<T>& p2);
00226 
00227 
00228 }
00229 #endif
00230 

Generated on Sun Sep 20 22:07:59 2009 for CVR-Lib by Doxygen 1.5.8