Function calculateInscribedDiameter in directory linuxcnc\src\emc\tp\

More
5 years 7 months ago #202559 by mil818
/**
* Calculate the diameter of a circle incscribed on a central cross section of a 3D
* rectangular prism.
*
* @param normal normal direction of plane slicing prism.
* @param extents distance from center to one corner of the prism.
* @param diameter diameter of inscribed circle on cross section.
*
*/
int calculateInscribedDiameter(PmCartesian const * const normal,
PmCartesian const * const bounds, double * const diameter)
{
if (!normal ) {
return TP_ERR_MISSING_INPUT;
}

double n_mag;
pmCartMagSq(normal, &n_mag);
double mag_err = fabs(1.0 - n_mag);
if (mag_err > pmSqrt(TP_POS_EPSILON)) {
/*rtapi_print_msg(RTAPI_MSG_ERR,"normal vector <%.12g,%.12f,%.12f> has magnitude error = %e\n",*/
/*normal->x,*/
/*normal->y,*/
/*normal->z,*/
/*mag_err);*/
return TP_ERR_FAIL;
}

PmCartesian planar_x,planar_y,planar_z;

//Find perpendicular component of unit directions
// FIXME Assumes normal is unit length

/* This section projects the X / Y / Z unit vectors onto the plane
* containing the motions. The operation is done "backwards" here due to a
* quirk with posemath.
*
*/
pmCartScalMult(normal, -normal->x, &planar_x);
pmCartScalMult(normal, -normal->y, &planar_y);
pmCartScalMult(normal, -normal->z, &planar_z);

planar_x.x += 1.0;
planar_y.y += 1.0;
planar_z.z += 1.0;

pmCartAbs(&planar_x, &planar_x);
pmCartAbs(&planar_y, &planar_y);
pmCartAbs(&planar_z, &planar_z);

// Crude way to prevent divide-by-zero-error
planar_x.x = fmax(planar_x.x,TP_POS_EPSILON);
planar_y.y = fmax(planar_y.y,TP_POS_EPSILON);
planar_z.z = fmax(planar_z.z,TP_POS_EPSILON);

double x_scale, y_scale, z_scale;
pmCartMag(&planar_x, &x_scale);
pmCartMag(&planar_y, &y_scale);
pmCartMag(&planar_z, &z_scale);

double x_extent=0, y_extent=0, z_extent=0;
if (bounds->x != 0) {
x_extent = bounds->x / x_scale;
}
if (bounds->y != 0) {
y_extent = bounds->y / y_scale;
}
if (bounds->z != 0) {
z_extent = bounds->z / z_scale;
}

// Find the highest value to start from
*diameter = fmax(fmax(x_extent, y_extent),z_extent);

// Only for active axes, find the minimum extent
if (bounds->x != 0) {
*diameter = fmin(*diameter, x_extent);
}
if (bounds->y != 0) {
*diameter = fmin(*diameter, y_extent);
}
if (bounds->z != 0) {
*diameter = fmin(*diameter, z_extent);
}

return TP_ERR_OK;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Question : who could explain this function clearly ? Something is buffled now ?Because there is not figure to be shown ,it is hard to understand.

Please Log in to join the conversation.

More
5 years 7 months ago #202561 by mil818
/* compute components rel to center */
pmCartScalMult(&circle->rTan, cos(angle), &par);
pmCartScalMult(&circle->rPerp, sin(angle), &perp);

Question : (&circle->rTan ) * cos(angle) + (circle->rPerp)*sin(angle) ,what does it mean ?

Please Log in to join the conversation.

More
5 years 7 months ago #202562 by mil818
scale = angle / circle->angle;

/* add scaled vector in radial dir for spiral */
pmCartUnit(point, &par);
pmCartScalMult(&par, scale * circle->spiral, &par);
pmCartCartAdd(point, &par, point);

/* add scaled vector in helix dir */
pmCartScalMult(&circle->rHelix, scale, &perp);
pmCartCartAdd(point, &perp, point);

/* add to center vector for final result */
pmCartCartAdd(&circle->center, point, point);


~~~~~~~~~~~~~~~~~~~~~~~~~~
who could explain above calcuation formula clearly with figure ?

Please Log in to join the conversation.

More
5 years 7 months ago #202685 by 85422776
sorry, I am not clear for it .

Please Log in to join the conversation.

More
5 years 7 months ago #202719 by tommylight
@85422776
Be warned if you come back and add spam links you go.

Please Log in to join the conversation.

Time to create page: 0.088 seconds
Powered by Kunena Forum