MOAB: Mesh Oriented datABase  (version 5.3.0)
MBMesquite::MsqCircle Class Reference

Circle in R^3. More...

#include <MsqGeomPrim.hpp>

+ Collaboration diagram for MBMesquite::MsqCircle:

Public Member Functions

 MsqCircle ()
 MsqCircle (const Vector3D &p_center, const Vector3D &p_normal, double p_radius)
const Vector3Dcenter () const
const Vector3Dnormal () const
double radius () const
Vector3D radial_vector () const
 Get arbitrary radial vector (vector in plane with length equal to radius)
Vector3D closest (const Vector3D &point) const
bool closest (const Vector3D &point, Vector3D &point_on_circle, Vector3D &tangent_at_point) const

Static Public Member Functions

static bool three_point (const Vector3D &p1, const Vector3D &p2, const Vector3D &p3, MsqCircle &result)
static bool two_point (const Vector3D &center, const Vector3D &p1, const Vector3D &p2, MsqCircle &result)

Private Attributes

Vector3D mCenter
Vector3D mNormal
 unit normal
double mRadius

Detailed Description

Circle in R^3.

Definition at line 95 of file MsqGeomPrim.hpp.


Constructor & Destructor Documentation

Definition at line 103 of file MsqGeomPrim.hpp.

Referenced by three_point(), and two_point().

: mCenter( 0, 0, 0 ), mNormal( 0, 0, 0 ), mRadius( 0 ) {}
MBMesquite::MsqCircle::MsqCircle ( const Vector3D p_center,
const Vector3D p_normal,
double  p_radius 
) [inline]

Definition at line 105 of file MsqGeomPrim.hpp.

        : mCenter( p_center ), mNormal( p_normal / p_normal.length() ), mRadius( p_radius )
    {
    }

Member Function Documentation

Find closest point on circle to input position. Returns arbitrary location on circle if point is at center.

Definition at line 94 of file MsqGeomPrim.cpp.

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

Referenced by MBMesquite::CircleDomain::snap_to(), GeomPrimTest::test_circle_closest_to_point(), and GeomPrimTest::test_circle_closest_with_tangent().

{
    const Vector3D from_center = point - center();
    const Vector3D norm_proj   = normal() * ( normal() % from_center );  // unit normal!
    const Vector3D in_plane    = from_center - norm_proj;
    const double length        = in_plane.length();
    if( length < DBL_EPSILON )
        return center() + radial_vector();
    else
        return center() + in_plane * radius() / length;
}
bool MBMesquite::MsqCircle::closest ( const Vector3D point,
Vector3D point_on_circle,
Vector3D tangent_at_point 
) const

Find closest point on circle to input position, and tangent at that point. Fails and returns false if point is at center of circle.

Definition at line 106 of file MsqGeomPrim.cpp.

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

{
    const Vector3D from_center = point - center();
    Vector3D in_plane          = from_center - ( from_center % normal() );
    if( in_plane.length_squared() < DBL_EPSILON ) return false;

    result_pt   = center() + in_plane * radius() / in_plane.length();
    result_tngt = in_plane * normal();
    return true;
}

Get arbitrary radial vector (vector in plane with length equal to radius)

Definition at line 82 of file MsqGeomPrim.cpp.

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

Referenced by closest(), MBMesquite::CircleDomain::closest_point(), GeomPrimTest::test_circle_closest_to_point(), GeomPrimTest::test_sphere_intersect_sphere(), and MBMesquite::CircleDomain::vertex_normal_at().

{
    int min_idx = 0;
    if( normal()[1] < normal()[min_idx] ) min_idx = 1;
    if( normal()[2] < normal()[min_idx] ) min_idx = 2;
    Vector3D vect( 0, 0, 0 );
    vect[min_idx] = 1;
    vect          = normal() * vect;
    vect *= radius() / vect.length();
    return vect;
}
bool MBMesquite::MsqCircle::three_point ( const Vector3D p1,
const Vector3D p2,
const Vector3D p3,
MsqCircle result 
) [static]

Find circle passing through three points

Returns:
false if points are colinear, true otherwise.

Definition at line 56 of file MsqGeomPrim.cpp.

References center(), MBMesquite::MsqLine::closest(), MBMesquite::length(), MBMesquite::Vector3D::length_squared(), MsqCircle(), MBMesquite::MsqLine::point(), and radius().

Referenced by GeomPrimTest::test_circle_from_three_points().

{
    Vector3D norm = ( p1 - p2 ) * ( p3 - p2 );
    if( norm.length_squared() < DBL_EPSILON ) return false;

    MsqLine line1( 0.5 * ( p1 + p2 ), norm * ( p1 - p2 ) );
    MsqLine line2( 0.5 * ( p2 + p3 ), norm * ( p3 - p2 ) );
    double t_xsect;
    if( !line1.closest( line2, t_xsect ) ) return false;

    Vector3D center = line1.point( t_xsect );
    double radius   = ( ( center - p1 ).length() + ( center - p2 ).length() + ( center - p3 ).length() ) / 3.0;
    result          = MsqCircle( center, norm, radius );
    return true;
}
bool MBMesquite::MsqCircle::two_point ( const Vector3D center,
const Vector3D p1,
const Vector3D p2,
MsqCircle result 
) [static]

Find circle with center and two points

Returns:
false if points are colinear or not equidistant from center, true otherwise.

Definition at line 72 of file MsqGeomPrim.cpp.

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

Referenced by GeomPrimTest::test_circle_from_two_points().

{
    Vector3D norm = ( p1 - center ) * ( p2 - center );
    if( norm.length_squared() < DBL_EPSILON ) return false;

    double radius = 0.5 * ( ( center - p1 ).length() + ( center - p2 ).length() );
    result        = MsqCircle( center, norm, radius );
    return true;
}

Member Data Documentation

Definition at line 98 of file MsqGeomPrim.hpp.

unit normal

Definition at line 99 of file MsqGeomPrim.hpp.

Definition at line 100 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