Example #1
0
// general purpose facet-drop which calls xy_normal_length(), normal_length(), 
// and center_height() on the subclass
bool MillingCutter::facetDrop(CLPoint &cl, const Triangle &t) const { // Drop cutter at (cl.x, cl.y) against facet of Triangle t
    Point normal = t.upNormal(); // facet surface normal
    if ( isZero_tol( normal.z ) )  // vertical surface
        return false;  //can't drop against vertical surface
    assert( isPositive( normal.z ) );
    
    if ( ( isZero_tol(normal.x) ) && ( isZero_tol(normal.y) ) ) { // horizontal plane special case
        CCPoint cc_tmp( cl.x, cl.y, t.p[0].z, FACET);
        return cl.liftZ_if_inFacet(cc_tmp.z, cc_tmp, t);
    } else { // general case
        // plane containing facet:  a*x + b*y + c*z + d = 0, so
        // d = -a*x - b*y - c*z, where  (a,b,c) = surface normal
        double d = - normal.dot(t.p[0]);
        normal.normalize(); // make length of normal == 1.0
        Point xyNormal( normal.x, normal.y, 0.0);
        xyNormal.xyNormalize();
        // define the radiusvector which points from the cc-point to the cutter-center 
        Point radiusvector = this->xy_normal_length*xyNormal + this->normal_length*normal;
        CCPoint cc_tmp = cl - radiusvector; // NOTE xy-coords right, z-coord is not.
        cc_tmp.z = (1.0/normal.z)*(-d-normal.x*cc_tmp.x-normal.y*cc_tmp.y); // cc-point lies in the plane.
        cc_tmp.type = FACET;
        double tip_z = cc_tmp.z + radiusvector.z - this->center_height;
        return cl.liftZ_if_inFacet(tip_z, cc_tmp, t);
    }
}
bool CGraphicView::GetXYPointForDXFTextExport( const CPoint& screenPt, CPoint3D& worldPt )
{
	//get a ray that goes through screenPt from the front of the view frustum to the back of it
	CPoint3D nearPt, farPt;
	if( !Get3DPointFromScreen( screenPt, nearPt, 0.f ) )
		return false;
	if( !Get3DPointFromScreen( screenPt, farPt, 1.f ) )
		return false;
	CLine3D ray( nearPt, farPt );

	//now find out where in 3D space the ray passes through the z=0 plane
	CVector3D xyNormal( 0., 0., 1. );
	CPoint3D ptOnXYPlane( 0., 0., 0. );
	CPlane3D xyPlane( xyNormal, ptOnXYPlane );
	double denom = xyNormal.dot( CVector3D( farPt, nearPt ) );
	if( zero( denom ) ) return false;
	double num = xyNormal.dot( CVector3D( ptOnXYPlane, nearPt  ) );
	double s = num/denom;
	worldPt = ray.offset( s );
	
	if( true/*is world point valid*/ )
		return true;
	else return false;
}