⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plane.h

📁 一个用MATLAB语言编写的摄像机标定工具箱,内容丰富
💻 H
字号:
//
// plane.h
//
// $Id: plane.h,v 1.1.1.1 2001/02/28 00:28:38 cstolte Exp $
//

#ifndef SGL_PLANE_H
#define SGL_PLANE_H

#include <sgl/defs.h>
#include <sgl/vecmath3.h>

////////
// Plane

struct Plane {
    Plane() { }
    Plane(float aa, float bb, float cc, float dd)
	: a(aa), b(bb), c(cc), d(dd) { }
    Plane(const Point3 &p, const Normal3 &n);
    Plane(const Point3 &p, const Point3 &p1, const Point3 &p2);
    Plane(const Point3 &p, const Vector3 &v1, const Vector3 &v2);

    // is the point on, above, or below the plane?
    inline bool coincident(const Point3 &, double eps = 1e-5) const;
    inline bool above(const Point3 &) const;
    inline bool below(const Point3 &) const;

    // return the point of intersection of a ray starting at point p
    // in direction d with the plane.  Ignore hits closer than t0 and
    // farther away than *t.  Hit distance is returned in *t.
    bool intersect(const Point3 &p, const Vector3 &d, double t0,
		   double *t) const;

    // Return the distance from the point to the plane; the sign of
    // signed_distance tells if the point is above (+) or below (-)
    // the plane
    inline double distance(const Point3 &) const;
    inline double signed_distance(const Point3 &) const;

    // Given two planes that intersect, return a point on and the
    // direction of their line of intersection.  Returns false if the
    // planes don't intersect.
    bool line(const Plane &, Point3 *p, Vector3 *d) const;

private:
    friend std::ostream &operator<<(std::ostream &, const Plane &);

    void init(const Point3 &p, const Normal3 &n);

    float a, b, c, d;
};

inline bool 
Plane::coincident(const Point3 &p, double eps) const
{
    return fabs(a * p.x + b * p.y + c * p.z + d) < eps;
}

inline bool 
Plane::above(const Point3 &p) const
{
    return (a * p.x + b * p.y + c * p.z > 0);
}

inline bool 
Plane::below(const Point3 &p) const
{
    return (a * p.x + b * p.y + c * p.z < 0);
}

inline double
Plane::distance(const Point3 &p) const
{
    return (fabs(p.x * a + p.y * b + p.z * c + d) /
	    (a*a + b*b + c*c));
}

inline double
Plane::signed_distance(const Point3 &p) const
{
    return (p.x * a + p.y * b + p.z * c + d) /
	(a*a + b*b + c*c);
}

#endif // SGL_PLANE_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -