Skip to content

Commit

Permalink
refactor(changeel): ChangeToArc3D refactor + using manvector
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandini committed Sep 19, 2023
1 parent 106d77d commit 5ddf9f9
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions SpecialMaps/tpzchangeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,24 +435,25 @@ TPZGeoEl * TPZChangeEl::ChangeToArc3D(TPZGeoMesh *mesh, const int64_t ElemIndex,

auto CreateMidNode = [](const TPZVec<REAL> &x1, const TPZVec<REAL> &x2,
const REAL r,
const TPZVec<REAL> &xcenter){
TPZVec<REAL> x3(3,0);
const auto &xc = xcenter[0];
const auto &yc = xcenter[1];
const auto &zc = xcenter[2];
const TPZVec<REAL> &xc){
TPZManVector<REAL,3> 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;
};

Expand Down

0 comments on commit 5ddf9f9

Please sign in to comment.