MOAB: Mesh Oriented datABase  (version 5.4.1)
MBMesquite::MsqSphere Class Reference

Sphere. More...

#include <MsqGeomPrim.hpp>

+ Collaboration diagram for MBMesquite::MsqSphere:

Public Member Functions

 MsqSphere (const Vector3D &p_center, double p_radius)
const Vector3Dcenter () const
double radius () const
Vector3D closest (const Vector3D &point) const
bool closest (const Vector3D &point, Vector3D &point_on_sphere, Vector3D &normal_at_point) const
double distance (const Vector3D &point) const
bool intersect (const MsqPlane &plane, MsqCircle &result) const
bool intersect (const MsqSphere &sphere, MsqCircle &result) const

Private Attributes

Vector3D mCenter
double mRadius

Detailed Description

Sphere.

Definition at line 197 of file MsqGeomPrim.hpp.


Constructor & Destructor Documentation

MBMesquite::MsqSphere::MsqSphere ( const Vector3D p_center,
double  p_radius 
) [inline]

Definition at line 204 of file MsqGeomPrim.hpp.

: mCenter( p_center ), mRadius( p_radius ) {}

Member Function Documentation

Get location on sphere closest to input location. Returns arbitrary point if input location is at center.

Definition at line 158 of file MsqGeomPrim.cpp.

References center(), MBMesquite::Vector3D::length(), and radius().

Referenced by GeomPrimTest::test_sphere_closest_to_point().

{
    Vector3D diff = point - center();
    double len    = diff.length();
    if( len < DBL_EPSILON )
    {
        // pick any point
        diff = Vector3D( 1, 0, 0 );
        len  = 1;
    }

    return center() + diff * radius() / len;
}
bool MBMesquite::MsqSphere::closest ( const Vector3D point,
Vector3D point_on_sphere,
Vector3D normal_at_point 
) const

Get location on sphere closest to input location, and normal at closest point.

Returns:
false if input point is at center, true otherwise.

Definition at line 172 of file MsqGeomPrim.cpp.

References center(), MBMesquite::Vector3D::length(), and radius().

{
    normal_at_point = point - center();
    double len      = normal_at_point.length();
    if( len < DBL_EPSILON ) return false;

    normal_at_point /= len;
    point_on_sphere = center() + radius() * normal_at_point;
    return true;
}
double MBMesquite::MsqSphere::distance ( const Vector3D point) const [inline]

Definition at line 224 of file MsqGeomPrim.hpp.

References center(), MBMesquite::length(), and radius.

Referenced by GeomPrimTest::test_sphere_intersect_sphere().

    {
        return fabs( ( center() - point ).length() - radius() );
    }
bool MBMesquite::MsqSphere::intersect ( const MsqPlane plane,
MsqCircle result 
) const

Intersect plane with sphere

Returns:
true if intersection exists, false otherwise.

Definition at line 183 of file MsqGeomPrim.cpp.

References center(), MBMesquite::MsqPlane::closest(), MBMesquite::Vector3D::length_squared(), MBMesquite::MsqPlane::normal(), and radius().

Referenced by GeomPrimTest::test_sphere_intersect_plane(), and GeomPrimTest::test_sphere_intersect_sphere().

{
    const Vector3D plane_pt  = plane.closest( center() );
    const Vector3D plane_dir = plane_pt - center();
    const double dir_sqr     = plane_dir.length_squared();
    if( dir_sqr < DBL_EPSILON )
    {  // plane passes through center of sphere
        result = MsqCircle( center(), plane.normal(), radius() );
        return true;
    }

    double rad_sqr = radius() * radius() - plane_dir.length_squared();
    if( rad_sqr < 0 )  // no intersection
        return false;

    result = MsqCircle( plane_pt, plane_dir, sqrt( rad_sqr ) );
    return true;
}
bool MBMesquite::MsqSphere::intersect ( const MsqSphere sphere,
MsqCircle result 
) const

Intersect spheres

Returns:
true if intersection exists, false otherwise.

Definition at line 202 of file MsqGeomPrim.cpp.

References center(), dist(), MBMesquite::Vector3D::length(), and radius().

{
    const Vector3D d  = sphere.center() - center();
    const double dist = d.length();
    if( dist > ( radius() + sphere.radius() ) ) return false;

    const double r1_sqr = radius() * radius();
    const double r2_sqr = sphere.radius() * sphere.radius();
    const double f      = ( d % d + r1_sqr - r2_sqr ) / 2;
    // const double d1 = f / dist;

    const double rad = sqrt( r1_sqr - f * f / ( d % d ) );
    Vector3D c       = center() + d * f / ( d % d );
    result           = MsqCircle( c, d, rad );
    return true;
}

Member Data Documentation

Definition at line 200 of file MsqGeomPrim.hpp.

Definition at line 201 of file MsqGeomPrim.hpp.

List of all members.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines