Foam::cylindricalCS Foam::arcEdge::calcAngle() { vector a = p2_ - p1_; vector b = p3_ - p1_; // find centre of arcEdge scalar asqr = a & a; scalar bsqr = b & b; scalar adotb = a & b; scalar denom = asqr*bsqr - adotb*adotb; if (mag(denom) < VSMALL) { FatalErrorInFunction << denom << abort(FatalError); } scalar fact = 0.5*(bsqr - adotb)/denom; point centre = 0.5*a + fact*((a ^ b) ^ a); centre += p1_; // find position vectors w.r.t. the arcEdge centre vector r1(p1_ - centre); vector r2(p2_ - centre); vector r3(p3_ - centre); // find angles angle_ = radToDeg(acos((r3 & r1)/(mag(r3) * mag(r1)))); // check if the vectors define an exterior or an interior arcEdge if (((r1 ^ r2) & (r1 ^ r3)) < 0.0) { angle_ = 360.0 - angle_; } vector tempAxis; if (angle_ <= 180.0) { tempAxis = r1 ^ r3; if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001) { tempAxis = r1 ^ r2; } } else { tempAxis = r3 ^ r1; } radius_ = mag(r3); // set up and return the local coordinate system return cylindricalCS("arcEdgeCS", centre, tempAxis, r1); }
Foam::cylindricalCS Foam::arcEdge::calcAngle() { vector a = p2_ - p1_; vector b = p3_ - p1_; // find centre of arcEdge scalar asqr = a & a; scalar bsqr = b & b; scalar adotb = a & b; scalar denom = asqr*bsqr - adotb*adotb; if (mag(denom) < VSMALL) { FatalErrorIn("cylindricalCS arcEdge::calcAngle()") << "Invalid arc definition - are the points co-linear? Denom =" << denom << abort(FatalError); } scalar fact = 0.5*(bsqr - adotb)/denom; vector centre = 0.5*a + fact*((a ^ b) ^ a); centre += p1_; // find position vectors w.r.t. the arcEdge centre vector r1(p1_ - centre); vector r2(p2_ - centre); vector r3(p3_ - centre); // find angles scalar tmp = (r3&r1)/(mag(r3)*mag(r1)); angle_ = acos(tmp)*180.0/mathematicalConstant::pi; // check if the vectors define an exterior or an interior arcEdge if (((r1 ^ r2)&(r1 ^ r3)) < 0.0) angle_ = 360 - angle_; vector tempAxis(0.0,0.0,0.0); if (angle_ <= 180.0) { tempAxis = r1 ^ r3; if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001) tempAxis = r1 ^ r2; } else { tempAxis = r3 ^ r1; } radius_ = mag(r3); // set up and return the local coordinate system return cylindricalCS("tmpCS", centre, tempAxis, r1); }