Logo Search packages:      
Sourcecode: sailcut version File versions  Download package

vect_geom.h

/*
 * Copyright (C) 2002-2004 Jeremy Lainé
 * See AUTHORS file for a full list of contributors.
 * 
 * $Id: vect_geom.h,v 1.18 2004/10/26 19:30:53 jeremy_laine Exp $
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef GEOCPP_VECT_GEOM_H
#define GEOCPP_VECT_GEOM_H

#include "vect_real.h"

class CMatrix;

/***************************************
 
         Generic 2D/3D vectors
 
***************************************/

/** Generic two dimensional real-valued vector.
 */
00037 class CVector2d : public CVector
{
public:
    // construction & destruction
    CVector2d(const CVector &v);
    CVector2d(const CMatrix &m);
    /** Constructor. */
00044     CVector2d(const real &x = 0, const real &y = 0)
    {
        m_dim = 2;
        m_data = new real[2];
        m_data[0] = x;
        m_data[1] = y;
    }

    /** Returns the first coordinate. */
00053     real &x(void)
    {
        return m_data[0];
    }
    /** Returns the second coordinate. */
00058     real &y(void)
    {
        return m_data[1];
    }

    /** Assignment operator. */
00064     CVector2d &operator=(const CVector2d &v)
    {
        memcpy(m_data,v.m_data,sizeof(real)*2);
        return *this;
    }

};


/** Generic three dimensional real-valued vector.
 */
00075 class CVector3d : public CVector
{
public:
    // construction & destruction
    CVector3d(const CVector& v);

    /** Column matrix to vector conversion. */
    CVector3d(const CMatrix& m);
    /** Constructor .*/
00084     CVector3d(const real &x = 0, const real &y = 0, const real &z = 0)
    {
        m_dim = 3;
        m_data = new real[3];
        m_data[0] = x;
        m_data[1] = y;
        m_data[2] = z;
    }

    // access to coords
    /** Returns the first coordinate. */
00095     real &x(void) const
    {
        return m_data[0];
    }
    /** Returns the second coordinate. */
00100     real &y(void) const
    {
        return m_data[1];
    }
    /** Returns the third coordinate. */
00105     real &z(void) const
    {
        return m_data[2];
    }

    // 3D only!
    /** Cross product, produces a vector orthogonal
     *  to the two original vectors. */
    CVector3d cross(const CVector3d &);
    /** Assignment. */
00115     CVector3d &operator=(const CVector3d &v)
    {
        memcpy(m_data,v.m_data,sizeof(real)*3);
        return *this;
    }
};



/***************************************
 
              2D/3D points
 
***************************************/

/** 2d real-valued point
 */
typedef CVector2d CPoint2d;

/** 3d real-valued point
 */
typedef CVector3d CPoint3d;

/***************************************
 
                3D box
 
***************************************/

/** 3D box.
 */
00146 class CRect3d
{
public:
    CRect3d()
    {}
    ;
    ~CRect3d()
    {}
    ;

    // operators
    CRect3d operator+ (const CVector3d &transl) const;
    CRect3d operator* (const real r) const;

    /** Return the box's center. */
00161     CPoint3d center()
    {
        return 0.5 * (min + max);
    };
    /** Return the box's width. */
00166     real width() const
    {
        return max.x()-min.x();
    };
    /** Return the box's height. */
00171     real height() const
    {
        return max.y()-min.y();
00174     };

    /** lower-left corner */
    CPoint3d min;
    /** top-right corner */
00179     CPoint3d max;

};

#endif

Generated by  Doxygen 1.6.0   Back to index