Trapezoidal Teacups -- Geometry Test (Corrected) -- 12-10-2015
Phil Weinstein, CADSWES ... go to problem
Rectangular | Trapezoidal Normal |
Trapezoidal Rectangular |
Trapezoidal Inverted |
Code |
// returns success indication bool TeacupGfxItem::computeTrapezoidValueDims ( TcupGeom geom, // Input double pix2PerUnitVal, // Input, square pixel per unit val double value, // Input double& retValueHeight, // Returned double& retValueWidth) const // Returned ... ... ... ... ... ... // ******************************** // *** Geometric Computations *** // ******************************** //---------------------------------------------------------------------- // UNITS: pixels and square-pixels. // // KNOWN: [H3] refHgt -- reference trapezoid height // KNOWN: [L3] maxTopWid -- reference trapezoid top width // KNOWN: [L1] botWid -- trapezoid bottom width (both trapezoids) // KNOWN: [V3] cupArea -- reference trapezoid area // KNOWN: [V1] valArea -- value trapezoid area // // SOLVE FOR: [H1] retValueHeight -- value trapezoid height // SOLVE FOR: [L2] retValueWidth -- value trapezoid top width // // // +----------- L3 -----------+ ---- ---- // + + | | // + [V2] + H2 | // + + | | // +------- L2 -------+ ---- H3 // + + | | // + [V1] + H1 | // + + | | // +--- L1 ---+ ---- ---- // // V3 == V1 + V2 // //---------------------------------------------------------------------- const double H3 = refHgt; const double L3 = maxTopWid; const double L1 = botWid; const double V1 = valArea; if (fabs (H3) < NEGL) return (false); //----->> const double L2_squared = (2.0 * V1 * (L3 - L1) / H3) + (L1 * L1); // Note: It's reasonable to clip L2 to zero in the case of L2_squared // being negative. This occurs in the case of an "inverted" trapezoid // cup (with the top narrower than the bottom), and the "current" value // overflowing the maximum value. double L2 (0.0); static int overflowCnt (0); if (L2_squared < 0.0) ++overflowCnt; // diag breakpoint else L2 = sqrt (L2_squared); if (fabs (L1 + L2) < NEGL) return (false); //----->> const double H1 = (2.0 * V1) / (L1 + L2); retValueHeight = H1; retValueWidth = L2; return (true); }--- (end) ---