plane.h

Go to the documentation of this file.
00001 /*
00002  * plane.h
00003  *
00004  * Copyright (C) 2009  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Basic 2D plane as represented in 3D space.
00032  */
00033 
00034 #ifndef WAVEPACKET_PLANE_H__
00035 #define WAVEPACKET_PLANE_H__
00036 
00037 // includes --------------------------------------------------------------------
00038 #include "geometry_3d.h"
00039 
00040 
00041 /// \ingroup geometry
00042 /*@{*/
00043 
00044 
00045 // common typedefs -------------------------------------------------------------
00046 
00047 
00048 /// basic 2D plane in 3D space.  This is composed of a normal (vector), and
00049 ///   a distance D (along the normal) from the origin.
00050 ///
00051 /// Note that a point p in the plane satisfies the equation n.p = d.
00052 ///
00053 /// Likewise, the distance from any point p to the plane is n.p - d (= 0 for
00054 ///     points p in the plane, obviously).
00055 struct plane_t {
00056         plane_t(void) throw() { }
00057 
00058         void clear(void) throw() {
00059                         n.clear();
00060                         d = 0.0;
00061                 }
00062 
00063         void dump(IN const char * msg) const throw() {
00064                         DPRINTF("%s (plane): n = (%6.3f, %6.3f, %6.3f)  d = %7.2f",
00065                             msg, n.x, n.y, n.z, d);
00066                 }
00067 
00068         /// returns distance from point to plane measured along normal
00069         float distance(IN const point3d_t& p) const throw() {
00070                         return dotProduct(p, n) - d;
00071                 }
00072 
00073         // data fields ---------------------------------------------------------
00074         point3d_t       n;      ///< n is the normal vector to the plane
00075         float           d;      ///< d is the distance to origin along normal
00076 };
00077 
00078 
00079 
00080 /// given two planes (A and B) return the line of intersection between them.
00081 /// Returns false if the planes are parallel (or coincident), in which case
00082 ///     there is no single line of intersection.
00083 /// The intersection line is defined as p(t) = p0 + t pt.
00084 bool getLineOfIntersection(IN const plane_t& A, IN const plane_t& B,
00085                                 OUT point3d_t& p0, OUT point3d_t& pt) throw();
00086 
00087 
00088 #endif  // WAVEPACKET_PLANE_H__
00089