cgma
CubitPlane.hpp
Go to the documentation of this file.
00001 //- Class: CubitPlane
00002 //-
00003 //- Description: This file defines the CubitPlane class which is a
00004 //- three-dimensional planar surface defined by the equation  
00005 //- {Ax + By + Cz + D = 0}. Plane normal is normalized
00006 //- Only basic functionality required by other Cubit classes is 
00007 //- currently supported.
00008 //-
00009 //- Owner: Greg Sjaardema
00010 //- Checked by: Tony Edwards 8/18/94
00011 //- Version: $Id: 
00012 
00013 #ifndef CUBITPLANE_HPP
00014 #define CUBITPLANE_HPP
00015 
00016 template <class X> class DLIList;
00017 #include "CubitVector.hpp"
00018 #include "CubitPlaneStruct.h"
00019 #include "CGMUtilConfigure.h"
00020 #include <vector>
00021 
00022 class CUBIT_UTIL_EXPORT CubitPlane
00023 {
00024 public:
00025   
00026     //- Heading: Constructors and Destructor
00027   CubitPlane(); 
00028     //- Default constructor.
00029   
00030   CubitPlane(const double A, const double B,
00031              const double C, const double D);
00032     //- Constructor: create plane from three components of normal and 
00033     //- coefficient
00034   
00035   CubitPlane(const CubitVector &Normal, const double D);
00036     //- Constructor: create plane from plane normal and coefficient.
00037   
00038   CubitPlane(const CubitVector &Normal, const CubitVector &point);
00039     //- Constructor: create plane from plane normal that passes through point.
00040   
00041   CubitPlane(DLIList<CubitVector> &positions);
00042     //- Constructor: create plane closest to the set of points in {positions} 
00043     //- using Newell's Method.
00044   
00045   CubitPlane(const CubitPlane& copy_from);  //- Copy Constructor
00046   
00047   CubitPlane(const CubitPlaneStruct& from);  
00048   
00049   int mk_plane_with_points(const CubitVector& vector1,
00050                            const CubitVector& vector2,
00051                            const CubitVector& vector3);
00052     //- Create a plane given three points represented as 
00053     //- CubitVectors.
00054     //- Return a CUBIT_FAILURE if the points are collinear.
00055 
00056   //- fit a plane through the input points.
00057   bool fit_points(const std::vector<CubitVector> &positions);
00058   
00059   const CubitVector& normal() const;
00060     //- Return Plane normal (normalized)
00061 
00062   void normal(const CubitVector &temp_normal);
00063     //- set the normal for this plane
00064   
00065   double coefficient() const;
00066     //- Return the coefficient
00067   
00068   void coefficient(const double temp_coeff);
00069     //- set the coefficient
00070 
00071   void set(const CubitVector &Normal, const CubitVector &point);
00072     //- redefine plane using normal and point on plane
00073   
00074     //- Heading: Other Functions
00075   CubitVector point_on_plane() const;
00076     //- Returns a random point on the plane.
00077   
00078   double distance(const CubitVector &vector) const;
00079     //- Calculates the distance from {vector} to plane. If the point lies
00080     //- behind the plane (the opposite direction than the normal points),
00081     //- the returned distance will be negative.
00082   
00083   CubitVector intersect(const CubitVector &base,
00084                         const CubitVector &direction) const;
00085     //- Calculate intersection of line from {base} in direction {direction}
00086     //- and plane {this}.
00087     //- Returns coordinates of intersection in a CubitVector.
00088   
00089   int intersect(const CubitPlane &other_plane,
00090                 CubitVector &origin, CubitVector &vector) const;
00091     //- Calculate the intersection of {this} with {other_plane}
00092     //- Returns a point on the intersection line in {origin} and the
00093     //- direction of the intersection line in {vector}.
00094     //- Returns CUBIT_FALSE if the planes are coplanar
00095     
00096   CubitVector project( const CubitVector& point ) const;
00097     //- Project a point onto plane
00098   
00099   void reverse()
00100   { normal_ = -normal_; d_ = -d_; }
00101     //- flip the normal of the plane
00102 
00103   CubitPlane& operator=(const CubitPlane &plane);
00104     //- assignment
00105   
00106   CubitPlane &operator=(const CubitPlaneStruct &from);
00107 
00108   operator CubitPlaneStruct() 
00109     {
00110       CubitPlaneStruct to;
00111       to.normal_ = normal_;
00112       to.d_ = d_;
00113       return to;
00114     }
00115 
00116 private:
00117   
00118   CubitVector normal_;  //- Normal to plane.
00119   double d_;            //- Coefficient
00120   
00121 };
00122 
00123 inline const CubitVector& CubitPlane::normal() const { return normal_; }
00124 
00125 inline void CubitPlane::normal(const CubitVector &temp_normal)
00126 {normal_ = temp_normal;}
00127 
00128 inline double CubitPlane::coefficient() const { return d_; }
00129 inline void CubitPlane::coefficient(const double temp_coeff)
00130 {d_ = temp_coeff; }
00131 
00132 inline CubitPlane::CubitPlane(const CubitPlaneStruct &from)  
00133 {
00134   normal_ = from.normal_;
00135   d_ = from.d_;
00136 }
00137 
00138 #endif
00139 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines