From 5ddf9f9620417869ef5ca0325272ea4c8d8b0528 Mon Sep 17 00:00:00 2001 From: orlandini Date: Tue, 5 Sep 2023 10:47:41 -0300 Subject: [PATCH] refactor(changeel): ChangeToArc3D refactor + using manvector --- SpecialMaps/tpzchangeel.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/SpecialMaps/tpzchangeel.cpp b/SpecialMaps/tpzchangeel.cpp index e220a4f26..9aa3f7172 100644 --- a/SpecialMaps/tpzchangeel.cpp +++ b/SpecialMaps/tpzchangeel.cpp @@ -435,24 +435,25 @@ TPZGeoEl * TPZChangeEl::ChangeToArc3D(TPZGeoMesh *mesh, const int64_t ElemIndex, auto CreateMidNode = [](const TPZVec &x1, const TPZVec &x2, const REAL r, - const TPZVec &xcenter){ - TPZVec x3(3,0); - const auto &xc = xcenter[0]; - const auto &yc = xcenter[1]; - const auto &zc = xcenter[2]; + const TPZVec &xc){ + TPZManVector x3(3,0); - //first we get its distance from xc - x3[0] = (x1[0] + x2[0])/2 - xc; - x3[1] = (x1[1] + x2[1])/2 - yc; - x3[2] = (x1[2] + x2[2])/2 - zc; + //first we get the midpoint's direction (bissecting the arc) + //this wont work if the angle between the vectors is pi + REAL vecnorm{0}; + for(int ix = 0; ix < 3; ix++){ + const auto val = (x1[ix] + x2[ix])/2 - xc[ix]; + x3[ix] = val; + vecnorm += val*val; + } //norm of the vector - const auto vecnorm = sqrt(x3[0]*x3[0] + x3[1]*x3[1] + x3[2]*x3[2]); + vecnorm = sqrt(vecnorm); //mid-arc coordinates - x3[0] = xc + r * x3[0]/vecnorm; - x3[1] = yc + r * x3[1]/vecnorm; - x3[2] = zc + r * x3[2]/vecnorm; + for(int ix = 0; ix < 3; ix++){ + x3[ix] = xc[ix] + r * x3[ix]/vecnorm; + } return x3; };