Changeset 273382
- Timestamp:
- Apr 13, 2010, 1:22:42 PM (16 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, Candidate_v1.7.0, Candidate_v1.7.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 1bd79e
- Parents:
- 72e7fa
- Location:
- src
- Files:
-
- 26 edited
-
Legacy/oldmenu.cpp (modified) (13 diffs)
-
Plane.cpp (modified) (7 diffs)
-
SingleVector.cpp (modified) (8 diffs)
-
analysis_correlation.cpp (modified) (10 diffs)
-
atom.cpp (modified) (4 diffs)
-
atom_trajectoryparticle.cpp (modified) (1 diff)
-
bond.cpp (modified) (2 diffs)
-
boundary.cpp (modified) (9 diffs)
-
builder.cpp (modified) (3 diffs)
-
ellipsoid.cpp (modified) (7 diffs)
-
molecule.cpp (modified) (11 diffs)
-
molecule.hpp (modified) (1 diff)
-
molecule_dynamics.cpp (modified) (4 diffs)
-
molecule_fragmentation.cpp (modified) (1 diff)
-
molecule_geometry.cpp (modified) (15 diffs)
-
molecule_graph.cpp (modified) (1 diff)
-
molecule_template.hpp (modified) (1 diff)
-
moleculelist.cpp (modified) (2 diffs)
-
tesselation.cpp (modified) (63 diffs)
-
tesselationhelpers.cpp (modified) (19 diffs)
-
test/ActOnAlltest.hpp (modified) (2 diffs)
-
unittests/ActOnAllUnitTest.cpp (modified) (1 diff)
-
unittests/vectorunittest.cpp (modified) (5 diffs)
-
vector.cpp (modified) (33 diffs)
-
vector.hpp (modified) (2 diffs)
-
vector_ops.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Legacy/oldmenu.cpp
r72e7fa r273382 103 103 dialog->queryVector("Enter reference coordinates.",&x,mol->cell_size,true); 104 104 dialog->queryVector("Enter relative coordinates.",&first->x,mol->cell_size,false); 105 first->x .AddVector(&x);105 first->x += x; 106 106 dialog->display(); 107 107 delete dialog; … … 168 168 */ 169 169 // calc axis vector 170 x.CopyVector(&second->x); 171 x.SubtractVector(&third->x); 170 x= second->x - third->x; 172 171 x.Normalize(); 173 172 Log() << Verbose(0) << "x: " << x << endl; … … 178 177 179 178 // rotate vector around first angle 180 first->x .CopyVector(&x);179 first->x = x; 181 180 first->x = RotateVector(first->x,z,b - M_PI); 182 181 Log() << Verbose(0) << "Rotated vector: " << first->x << endl, 183 182 // remove the projection onto the rotation plane of the second angle 184 n .CopyVector(&y);185 n.Scale(first->x.ScalarProduct( &y));183 n = y; 184 n.Scale(first->x.ScalarProduct(y)); 186 185 Log() << Verbose(0) << "N1: " << n << endl; 187 first->x .SubtractVector(&n);186 first->x -= n; 188 187 Log() << Verbose(0) << "Subtracted vector: " << first->x << endl; 189 n .CopyVector(&z);190 n.Scale(first->x.ScalarProduct( &z));188 n = z; 189 n.Scale(first->x.ScalarProduct(z)); 191 190 Log() << Verbose(0) << "N2: " << n << endl; 192 first->x .SubtractVector(&n);191 first->x -= n; 193 192 Log() << Verbose(0) << "2nd subtracted vector: " << first->x << endl; 194 193 195 194 // rotate another vector around second angle 196 n .CopyVector(&y);195 n = y; 197 196 n = RotateVector(n,x,c - M_PI); 198 197 Log() << Verbose(0) << "2nd Rotated vector: " << n << endl; 199 198 200 199 // add the two linear independent vectors 201 first->x .AddVector(&n);200 first->x += n; 202 201 first->x.Normalize(); 203 202 first->x.Scale(a); 204 first->x .AddVector(&second->x);203 first->x += second->x; 205 204 206 205 Log() << Verbose(0) << "resulting coordinates: " << first->x << endl; … … 277 276 } 278 277 mol->CenterEdge(&x); // make every coordinate positive 279 mol->Center.AddVector(&y); // translate by boundary 280 helper.CopyVector(&y); 281 helper.Scale(2.); 282 helper.AddVector(&x); 278 mol->Center += y; // translate by boundary 279 helper = (2*y)+x; 283 280 mol->SetBoxDimension(&helper); // update Box of atoms by boundary 284 281 break; … … 340 337 second = mol->AskAtom("Enter second atom: "); 341 338 342 n.CopyVector((const Vector *)&first->x); 343 n.SubtractVector((const Vector *)&second->x); 339 n = first->x - second->x; 344 340 n.Normalize(); 345 341 break; … … 408 404 second = mol->AskAtom("Enter second atom: "); 409 405 410 n.CopyVector((const Vector *)&first->x); 411 n.SubtractVector((const Vector *)&second->x); 406 n = first->x - second->x; 412 407 n.Normalize(); 413 408 break; … … 453 448 first = second; 454 449 second = first->next; 455 if (first->x.DistanceSquared( (const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...450 if (first->x.DistanceSquared(second->x) > tmp1*tmp1) // distance to first above radius ... 456 451 mol->RemoveAtom(first); 457 452 } … … 520 515 tmp1 = 0.; 521 516 if (first != second) { 522 x.CopyVector((const Vector *)&first->x); 523 x.SubtractVector((const Vector *)&second->x); 517 x = first->x - second->x; 524 518 tmp1 = x.Norm(); 525 519 } … … 536 530 for (int i=NDIM;i--;) 537 531 min[i] = 0.; 538 x.CopyVector((const Vector *)&first->x); 539 x.SubtractVector((const Vector *)&second->x); 532 x = first->x - second->x; 540 533 tmp1 = x.Norm(); 541 534 Log() << Verbose(1) << "Distance vector is " << x << "." << "/n" … … 549 542 third = mol->AskAtom("Enter last atom: "); 550 543 tmp1 = tmp2 = tmp3 = 0.; 551 x.CopyVector((const Vector *)&first->x); 552 x.SubtractVector((const Vector *)&second->x); 553 y.CopyVector((const Vector *)&third->x); 554 y.SubtractVector((const Vector *)&second->x); 544 x = first->x - second->x; 545 y = third->x - second->x; 555 546 Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": "; 556 Log() << Verbose(0) << (acos(x.ScalarProduct( (const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;547 Log() << Verbose(0) << (acos(x.ScalarProduct(y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl; 557 548 break; 558 549 case 'd': … … 777 768 y[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 778 769 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 779 x .AddVector(&y); // per factor one cell width further770 x += y; // per factor one cell width further 780 771 for (int k=count;k--;) { // go through every atom of the original cell 781 772 first = World::getInstance().createAtom(); // create a new body 782 first->x.CopyVector(vectors[k]); // use coordinate of original atom 783 first->x.AddVector(&x); // translate the coordinates 773 first->x = (*vectors[k]) + x; // use coordinate of original atom 784 774 first->type = Elements[k]; // insert original element 785 775 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) … … 793 783 // correct cell size 794 784 if (axis < 0) { // if sign was negative, we have to translate everything 795 x.Zero(); 796 x.AddVector(&y); 785 x = y; 797 786 x.Scale(-(faktor-1)); 798 787 mol->Translate(&x); … … 894 883 dialog->display(); 895 884 delete dialog; 896 mol->Center .AddVector((const Vector *)&x);885 mol->Center += x; 897 886 } 898 887 break; -
src/Plane.cpp
r72e7fa r273382 20 20 normalVector(new Vector()) 21 21 { 22 Vector x1, x2; 23 24 x1.CopyVector(&y1); 25 x1.SubtractVector(&y2); 26 x2.CopyVector(&y3); 27 x2.SubtractVector(&y2); 28 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 22 Vector x1 = y1 -y2; 23 Vector x2 = y3 -y2; 24 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(x2)) < MYEPSILON)) { 29 25 throw LinearDependenceException(__FILE__,__LINE__); 30 26 } … … 41 37 normalVector->Normalize(); 42 38 43 offset=normalVector->ScalarProduct( &y1);39 offset=normalVector->ScalarProduct(y1); 44 40 } 45 41 /** … … 51 47 offset(_offset) 52 48 { 53 Vector x1,x2; 54 x1.CopyVector(&y1); 55 x2.CopyVector(&y2); 56 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 49 Vector x1 = y1; 50 Vector x2 = y2; 51 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(x2)) < MYEPSILON)) { 57 52 throw LinearDependenceException(__FILE__,__LINE__); 58 53 } … … 84 79 normalVector(new Vector(_normalVector)) 85 80 { 86 offset = normalVector->ScalarProduct( &_offsetVector);81 offset = normalVector->ScalarProduct(_offsetVector); 87 82 } 88 83 … … 126 121 Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl; 127 122 //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl; 128 double factor1 = Direction.ScalarProduct( normalVector.get());123 double factor1 = Direction.ScalarProduct(*normalVector.get()); 129 124 if (fabs(factor1) < MYEPSILON) { // Uniqueness: line parallel to plane? 130 125 Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl; … … 132 127 } 133 128 134 double factor2 = Origin.ScalarProduct( normalVector.get());129 double factor2 = Origin.ScalarProduct(*normalVector.get()); 135 130 if (fabs(factor2-offset) < MYEPSILON) { // Origin is in-plane 136 131 Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl; … … 147 142 148 143 // test whether resulting vector really is on plane 149 ASSERT(fabs(res.ScalarProduct( normalVector.get()) - offset) < MYEPSILON,144 ASSERT(fabs(res.ScalarProduct((*normalVector.get())) - offset) < MYEPSILON, 150 145 "Calculated line-Plane intersection does not lie on plane."); 151 146 return res; -
src/SingleVector.cpp
r72e7fa r273382 119 119 TranslationVector.MatrixMultiplication(matrix); 120 120 // add onto the original vector to compare with 121 Shiftedy.CopyVector(y); 122 Shiftedy.AddVector(&TranslationVector); 121 Shiftedy = y + TranslationVector; 123 122 // get distance and compare with minimum so far 124 123 tmp = Distance(Shiftedy); … … 157 156 TranslationVector.MatrixMultiplication(matrix); 158 157 // add onto the original vector to compare with 159 Shiftedy.CopyVector(y); 160 Shiftedy.AddVector(&TranslationVector); 158 Shiftedy = y + TranslationVector; 161 159 // get distance and compare with minimum so far 162 160 tmp = DistanceSquared(Shiftedy); … … 180 178 // Output(out); 181 179 // Log() << Verbose(0) << endl; 182 TestVector .CopyVector(this);180 TestVector = *this; 183 181 TestVector.InverseMatrixMultiplication(matrix); 184 182 for(int i=NDIM;i--;) { // correct periodically … … 190 188 } 191 189 TestVector.MatrixMultiplication(matrix); 192 CopyVector( &TestVector);190 CopyVector(TestVector); 193 191 // Log() << Verbose(2) << "New corrected vector is: "; 194 192 // Output(out); … … 250 248 251 249 // first create part that is orthonormal to PlaneNormal with withdraw 252 temp = *this- PlaneOffset;250 temp = (*this )- PlaneOffset; 253 251 temp.MakeNormalTo(PlaneNormal); 254 252 temp.Scale(-1.); 255 253 // then add connecting vector from plane to point 256 temp += *this-PlaneOffset;257 double sign = temp.ScalarProduct( &PlaneNormal);254 temp += (*this)-PlaneOffset; 255 double sign = temp.ScalarProduct(PlaneNormal); 258 256 if (fabs(sign) > MYEPSILON) 259 257 sign /= fabs(sign); … … 271 269 Vector helper = y; 272 270 helper.Scale(-(ScalarProduct(y))); 273 AddVector( &helper);271 AddVector(helper); 274 272 }; 275 273 … … 556 554 { 557 555 bool result = false; 558 double factor = y1.ScalarProduct( this)/y1.NormSquared();556 double factor = y1.ScalarProduct(*this)/y1.NormSquared(); 559 557 Vector x1; 560 x1.CopyVector(&y1); 561 x1.Scale(factor); 562 SubtractVector(&x1); 558 x1 = factor * y1; 559 SubtractVector(x1); 563 560 for (int i=NDIM;i--;) 564 561 result = result || (fabs(x[i]) > MYEPSILON); … … 618 615 bool SingleVector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 619 616 { 620 Vector a; 621 a.CopyVector(this); 622 a.SubtractVector(&offset); 617 Vector a = (*this) - offset; 623 618 a.InverseMatrixMultiplication(parallelepiped); 624 619 bool isInside = true; -
src/analysis_correlation.cpp
r72e7fa r273382 55 55 if (Walker->nr < OtherWalker->nr) 56 56 if ((type2 == NULL) || (OtherWalker->type == type2)) { 57 distance = Walker->node->PeriodicDistance( OtherWalker->node, (*MolWalker)->cell_size);57 distance = Walker->node->PeriodicDistance(*(OtherWalker->node), (*MolWalker)->cell_size); 58 58 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; 59 59 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); … … 104 104 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; 105 105 if ((type1 == NULL) || (Walker->type == type1)) { 106 periodicX .CopyVector(Walker->node);106 periodicX = *(Walker->node); 107 107 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 108 108 // go through every range in xyz and get distance … … 110 110 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 111 111 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 112 checkX.Init(n[0], n[1], n[2]); 113 checkX.AddVector(&periodicX); 112 checkX = Vector(n[0], n[1], n[2]) + periodicX; 114 113 checkX.MatrixMultiplication(FullMatrix); 115 114 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++) … … 122 121 if (Walker->nr < OtherWalker->nr) 123 122 if ((type2 == NULL) || (OtherWalker->type == type2)) { 124 periodicOtherX .CopyVector(OtherWalker->node);123 periodicOtherX = *(OtherWalker->node); 125 124 periodicOtherX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 126 125 // go through every range in xyz and get distance … … 128 127 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++) 129 128 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) { 130 checkOtherX.Init(Othern[0], Othern[1], Othern[2]); 131 checkOtherX.AddVector(&periodicOtherX); 129 checkOtherX = Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX; 132 130 checkOtherX.MatrixMultiplication(FullMatrix); 133 distance = checkX.Distance( &checkOtherX);131 distance = checkX.Distance(checkOtherX); 134 132 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl; 135 133 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) ); … … 174 172 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; 175 173 if ((type == NULL) || (Walker->type == type)) { 176 distance = Walker->node->PeriodicDistance( point, (*MolWalker)->cell_size);174 distance = Walker->node->PeriodicDistance(*point, (*MolWalker)->cell_size); 177 175 Log() << Verbose(4) << "Current distance is " << distance << "." << endl; 178 176 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); … … 216 214 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; 217 215 if ((type == NULL) || (Walker->type == type)) { 218 periodicX .CopyVector(Walker->node);216 periodicX = *(Walker->node); 219 217 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 220 218 // go through every range in xyz and get distance … … 222 220 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 223 221 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 224 checkX.Init(n[0], n[1], n[2]); 225 checkX.AddVector(&periodicX); 222 checkX = Vector(n[0], n[1], n[2]) + periodicX; 226 223 checkX.MatrixMultiplication(FullMatrix); 227 distance = checkX.Distance( point);224 distance = checkX.Distance(*point); 228 225 Log() << Verbose(4) << "Current distance is " << distance << "." << endl; 229 226 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) ); … … 320 317 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl; 321 318 if ((type == NULL) || (Walker->type == type)) { 322 periodicX .CopyVector(Walker->node);319 periodicX = *(Walker->node); 323 320 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3 324 321 // go through every range in xyz and get distance … … 327 324 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++) 328 325 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) { 329 checkX.Init(n[0], n[1], n[2]); 330 checkX.AddVector(&periodicX); 326 checkX = Vector(n[0], n[1], n[2]) + periodicX; 331 327 checkX.MatrixMultiplication(FullMatrix); 332 328 triangle = Surface->FindClosestTriangleToVector(&checkX, LC); -
src/atom.cpp
r72e7fa r273382 33 33 { 34 34 type = pointer->type; // copy element of atom 35 x .CopyVector(&pointer->x); // copy coordination36 v .CopyVector(&pointer->v); // copy velocity35 x = pointer->x; // copy coordination 36 v = pointer->v; // copy velocity 37 37 FixedIon = pointer->FixedIon; 38 38 node = &x; … … 46 46 res->sort = &nr; 47 47 res->type = type; 48 res->x .CopyVector(&this->x);49 res->v .CopyVector(&this->v);48 res->x = this->x; 49 res->v = this->v; 50 50 res->FixedIon = FixedIon; 51 51 res->node = &x; … … 252 252 double atom::DistanceSquaredToVector(const Vector &origin) const 253 253 { 254 return origin.DistanceSquared( &x);254 return origin.DistanceSquared(x); 255 255 }; 256 256 … … 261 261 double atom::DistanceToVector(const Vector &origin) const 262 262 { 263 return origin.Distance( &x);263 return origin.Distance(x); 264 264 }; 265 265 -
src/atom_trajectoryparticle.cpp
r72e7fa r273382 49 49 // set forces 50 50 for (int i=NDIM;i++;) 51 Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance( &Sprinter->Trajectory.R.at(endstep)));51 Force->Matrix[0][nr][5+i] += 2.*constant*sqrt(Trajectory.R.at(startstep).Distance(Sprinter->Trajectory.R.at(endstep))); 52 52 }; 53 53 -
src/bond.cpp
r72e7fa r273382 119 119 double bond::GetDistance() const 120 120 { 121 return (leftatom->node->Distance( rightatom->node));121 return (leftatom->node->Distance(*rightatom->node)); 122 122 }; 123 123 … … 127 127 double bond::GetDistanceSquared() const 128 128 { 129 return (leftatom->node->DistanceSquared( rightatom->node));129 return (leftatom->node->DistanceSquared(*rightatom->node)); 130 130 }; -
src/boundary.cpp
r72e7fa r273382 78 78 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around 79 79 Neighbour = BoundaryPoints[axis].begin(); 80 DistanceVector.CopyVector(&runner->second.second->x); 81 DistanceVector.SubtractVector(&Neighbour->second.second->x); 80 DistanceVector = runner->second.second->x - Neighbour->second.second->x; 82 81 do { // seek for neighbour pair where it flips 83 82 OldComponent = DistanceVector[Othercomponent]; … … 85 84 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around 86 85 Neighbour = BoundaryPoints[axis].begin(); 87 DistanceVector.CopyVector(&runner->second.second->x); 88 DistanceVector.SubtractVector(&Neighbour->second.second->x); 86 DistanceVector = runner->second.second->x - Neighbour->second.second->x; 89 87 //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl; 90 88 } while ((runner != Neighbour) && (fabs(OldComponent / fabs( … … 98 96 //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl; 99 97 // now we have found the pair: Neighbour and OtherNeighbour 100 OtherVector.CopyVector(&runner->second.second->x); 101 OtherVector.SubtractVector(&OtherNeighbour->second.second->x); 98 OtherVector = runner->second.second->x - OtherNeighbour->second.second->x; 102 99 //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl; 103 100 //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl; … … 170 167 while (Walker->next != mol->end) { 171 168 Walker = Walker->next; 172 ProjectedVector.CopyVector(&Walker->x); 173 ProjectedVector.SubtractVector(MolCenter); 174 ProjectedVector.ProjectOntoPlane(&AxisVector); 169 ProjectedVector = Walker->x - (*MolCenter); 170 ProjectedVector.ProjectOntoPlane(AxisVector); 175 171 176 172 // correct for negative side 177 173 const double radius = ProjectedVector.NormSquared(); 178 174 if (fabs(radius) > MYEPSILON) 179 angle = ProjectedVector.Angle( &AngleReferenceVector);175 angle = ProjectedVector.Angle(AngleReferenceVector); 180 176 else 181 177 angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues 182 178 183 179 //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl; 184 if (ProjectedVector.ScalarProduct( &AngleReferenceNormalVector) > 0) {180 if (ProjectedVector.ScalarProduct(AngleReferenceNormalVector) > 0) { 185 181 angle = 2. * M_PI - angle; 186 182 } … … 197 193 Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl; 198 194 } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) { 199 helper.CopyVector(&Walker->x); 200 helper.SubtractVector(MolCenter); 195 helper = Walker->x - (*MolCenter); 201 196 const double oldhelperNorm = helper.NormSquared(); 202 helper.CopyVector(&BoundaryTestPair.first->second.second->x); 203 helper.SubtractVector(MolCenter); 197 helper = BoundaryTestPair.first->second.second->x - (*MolCenter); 204 198 if (helper.NormSquared() < oldhelperNorm) { 205 199 BoundaryTestPair.first->second.second = Walker; … … 251 245 { 252 246 Vector SideA, SideB, SideC, SideH; 253 SideA.CopyVector(&left->second.second->x); 254 SideA.SubtractVector(MolCenter); 255 SideA.ProjectOntoPlane(&AxisVector); 247 SideA = left->second.second->x - (*MolCenter); 248 SideA.ProjectOntoPlane(AxisVector); 256 249 // Log() << Verbose(1) << "SideA: " << SideA << endl; 257 250 258 SideB.CopyVector(&right->second.second->x); 259 SideB.SubtractVector(MolCenter); 260 SideB.ProjectOntoPlane(&AxisVector); 251 SideB = right->second.second->x -(*MolCenter); 252 SideB.ProjectOntoPlane(AxisVector); 261 253 // Log() << Verbose(1) << "SideB: " << SideB << endl; 262 254 263 SideC.CopyVector(&left->second.second->x); 264 SideC.SubtractVector(&right->second.second->x); 265 SideC.ProjectOntoPlane(&AxisVector); 255 SideC = left->second.second->x - right->second.second->x; 256 SideC.ProjectOntoPlane(AxisVector); 266 257 // Log() << Verbose(1) << "SideC: " << SideC << endl; 267 258 268 SideH.CopyVector(&runner->second.second->x); 269 SideH.SubtractVector(MolCenter); 270 SideH.ProjectOntoPlane(&AxisVector); 259 SideH = runner->second.second->x -(*MolCenter); 260 SideH.ProjectOntoPlane(AxisVector); 271 261 // Log() << Verbose(1) << "SideH: " << SideH << endl; 272 262 … … 277 267 const double h = SideH.Norm(); 278 268 // calculate the angles 279 const double alpha = SideA.Angle( &SideH);280 const double beta = SideA.Angle( &SideC);281 const double gamma = SideB.Angle( &SideH);282 const double delta = SideC.Angle( &SideH);269 const double alpha = SideA.Angle(SideH); 270 const double beta = SideA.Angle(SideC); 271 const double gamma = SideB.Angle(SideH); 272 const double delta = SideC.Angle(SideH); 283 273 const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.); 284 274 //Log() << Verbose(1) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl; … … 629 619 for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) 630 620 { // go through every triangle, calculate volume of its pyramid with CoG as peak 631 x.CopyVector(runner->second->endpoints[0]->node->node); 632 x.SubtractVector(runner->second->endpoints[1]->node->node); 633 y.CopyVector(runner->second->endpoints[0]->node->node); 634 y.SubtractVector(runner->second->endpoints[2]->node->node); 635 const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node)); 636 const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[2]->node->node)); 637 const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node)); 621 x = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[1]->node->node); 622 y = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[2]->node->node); 623 const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node)); 624 const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[2]->node->node)); 625 const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node)); 638 626 const double G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle 639 627 x = Plane(*(runner->second->endpoints[0]->node->node), 640 628 *(runner->second->endpoints[1]->node->node), 641 629 *(runner->second->endpoints[2]->node->node)).getNormal(); 642 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct( &x));630 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(x)); 643 631 const double h = x.Norm(); // distance of CoG to triangle 644 632 const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak) … … 917 905 if (DoRandomRotation) 918 906 CopyAtoms[Walker->nr]->x.MatrixMultiplication(Rotations); 919 CopyAtoms[Walker->nr]->x .AddVector(&AtomTranslations);920 CopyAtoms[Walker->nr]->x .AddVector(&FillerTranslations);921 CopyAtoms[Walker->nr]->x .AddVector(&CurrentPosition);907 CopyAtoms[Walker->nr]->x += AtomTranslations; 908 CopyAtoms[Walker->nr]->x += FillerTranslations; 909 CopyAtoms[Walker->nr]->x += CurrentPosition; 922 910 923 911 // insert into Filling -
src/builder.cpp
r72e7fa r273382 1817 1817 first = second; 1818 1818 second = first->next; 1819 if (first->x.DistanceSquared( (const Vector *)&third->x) > tmp1*tmp1) // distance to first above radius ...1819 if (first->x.DistanceSquared(third->x) > tmp1*tmp1) // distance to first above radius ... 1820 1820 mol->RemoveAtom(first); 1821 1821 } … … 2096 2096 y[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude 2097 2097 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times 2098 x .AddVector(&y); // per factor one cell width further2098 x += y; // per factor one cell width further 2099 2099 for (int k=count;k--;) { // go through every atom of the original cell 2100 2100 first = World::getInstance().createAtom(); // create a new body 2101 first->x.CopyVector(vectors[k]); // use coordinate of original atom 2102 first->x.AddVector(&x); // translate the coordinates 2101 first->x = (*vectors[k]) + x; 2103 2102 first->type = Elements[k]; // insert original element 2104 2103 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...) … … 2110 2109 // correct cell size 2111 2110 if (axis < 0) { // if sign was negative, we have to translate everything 2112 x.Zero(); 2113 x.AddVector(&y); 2114 x.Scale(-(faktor-1)); 2111 x =(-(faktor-1)) * y; 2115 2112 mol->Translate(&x); 2116 2113 } -
src/ellipsoid.cpp
r72e7fa r273382 42 42 43 43 // 1. translate coordinate system so that ellipsoid center is in origin 44 helper.CopyVector(&x); 45 helper.SubtractVector(&EllipsoidCenter); 46 RefPoint.CopyVector(&helper); 44 RefPoint = helper = x - EllipsoidCenter; 47 45 //Log() << Verbose(4) << "Translated given point is at " << RefPoint << "." << endl; 48 46 … … 86 84 87 85 // 5. determine distance between backtransformed point and x 88 distance = RefPoint.DistanceSquared( &helper);86 distance = RefPoint.DistanceSquared(helper); 89 87 //Log() << Verbose(4) << "Squared distance between intersection and RefPoint is " << distance << "." << endl; 90 88 … … 304 302 Candidate = (*Runner); 305 303 Log() << Verbose(2) << "Current picked node is " << **Runner << " with index " << index << "." << endl; 306 x[PointsPicked++] .CopyVector(Candidate->node); // we have one more atom picked304 x[PointsPicked++] = (*Candidate->node); // we have one more atom picked 307 305 current++; // next pre-picked atom 308 306 } … … 350 348 //Log() << Verbose(3) << "Current node is " << *Runner->second->node << " with " << value << " ... " << threshold << ": "; 351 349 if (value > threshold) { 352 x[PointsPicked] .CopyVector(Runner->second->node->node);350 x[PointsPicked] = (*Runner->second->node->node); 353 351 PointsPicked++; 354 352 //Log() << Verbose(0) << "IN." << endl; … … 387 385 Center.Zero(); 388 386 for (PointMap::iterator Runner = T->PointsOnBoundary.begin(); Runner != T->PointsOnBoundary.end(); Runner++) 389 Center .AddVector(Runner->second->node->node);387 Center += (*Runner->second->node->node); 390 388 Center.Scale(1./T->PointsOnBoundaryCount); 391 389 Log() << Verbose(1) << "Center is at " << Center << "." << endl; … … 405 403 // calculate some sensible starting values for parameter fit 406 404 MaxDistance = 0.; 407 MinDistance = x[0].ScalarProduct( &x[0]);405 MinDistance = x[0].ScalarProduct(x[0]); 408 406 for (int i=0;i<N;i++) { 409 distance = x[i].ScalarProduct( &x[i]);407 distance = x[i].ScalarProduct(x[i]); 410 408 if (distance > MaxDistance) 411 409 MaxDistance = distance; … … 414 412 } 415 413 //Log() << Verbose(2) << "MinDistance " << MinDistance << ", MaxDistance " << MaxDistance << "." << endl; 416 EllipsoidCenter .CopyVector(&Center); // use Center of Gravity as initial center of ellipsoid414 EllipsoidCenter = Center; // use Center of Gravity as initial center of ellipsoid 417 415 for (int i=0;i<3;i++) 418 416 EllipsoidAngle[i] = 0.; -
src/molecule.cpp
r72e7fa r273382 220 220 // Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl; 221 221 // create vector in direction of bond 222 InBondvector.CopyVector(&TopReplacement->x); 223 InBondvector.SubtractVector(&TopOrigin->x); 222 InBondvector = TopReplacement->x - TopOrigin->x; 224 223 bondlength = InBondvector.Norm(); 225 224 … … 240 239 matrix = ReturnFullMatrixforSymmetric(cell_size); 241 240 Orthovector1.MatrixMultiplication(matrix); 242 InBondvector.SubtractVector( &Orthovector1); // subtract just the additional translation241 InBondvector.SubtractVector(Orthovector1); // subtract just the additional translation 243 242 Free(&matrix); 244 243 bondlength = InBondvector.Norm(); … … 265 264 FirstOtherAtom = World::getInstance().createAtom(); // new atom 266 265 FirstOtherAtom->type = elemente->FindElement(1); // element is Hydrogen 267 FirstOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity266 FirstOtherAtom->v = TopReplacement->v; // copy velocity 268 267 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 269 268 if (TopReplacement->type->Z == 1) { // neither rescale nor replace if it's already hydrogen … … 274 273 } 275 274 InBondvector.Scale(&BondRescale); // rescale the distance vector to Hydrogen bond length 276 FirstOtherAtom->x .CopyVector(&TopOrigin->x); // set coordination to origin ...277 FirstOtherAtom->x .AddVector(&InBondvector); // ... and add distance vector to replacement atom275 FirstOtherAtom->x = TopOrigin->x; // set coordination to origin ... 276 FirstOtherAtom->x = InBondvector; // ... and add distance vector to replacement atom 278 277 AllWentWell = AllWentWell && AddAtom(FirstOtherAtom); 279 278 // Log() << Verbose(4) << "Added " << *FirstOtherAtom << " at: "; … … 316 315 } 317 316 } else { 318 Orthovector1.GetOneNormalVector( &InBondvector);317 Orthovector1.GetOneNormalVector(InBondvector); 319 318 } 320 319 //Log() << Verbose(3)<< "Orthovector1: "; … … 331 330 FirstOtherAtom->type = elemente->FindElement(1); 332 331 SecondOtherAtom->type = elemente->FindElement(1); 333 FirstOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity332 FirstOtherAtom->v = TopReplacement->v; // copy velocity 334 333 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 335 SecondOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity334 SecondOtherAtom->v = TopReplacement->v; // copy velocity 336 335 SecondOtherAtom->FixedIon = TopReplacement->FixedIon; 337 336 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father … … 388 387 SecondOtherAtom->type = elemente->FindElement(1); 389 388 ThirdOtherAtom->type = elemente->FindElement(1); 390 FirstOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity389 FirstOtherAtom->v = TopReplacement->v; // copy velocity 391 390 FirstOtherAtom->FixedIon = TopReplacement->FixedIon; 392 SecondOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity391 SecondOtherAtom->v = TopReplacement->v; // copy velocity 393 392 SecondOtherAtom->FixedIon = TopReplacement->FixedIon; 394 ThirdOtherAtom->v .CopyVector(&TopReplacement->v); // copy velocity393 ThirdOtherAtom->v = TopReplacement->v; // copy velocity 395 394 ThirdOtherAtom->FixedIon = TopReplacement->FixedIon; 396 395 FirstOtherAtom->father = NULL; // we are just an added hydrogen with no father … … 399 398 400 399 // we need to vectors orthonormal the InBondvector 401 AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector( &InBondvector);400 AllWentWell = AllWentWell && Orthovector1.GetOneNormalVector(InBondvector); 402 401 // Log() << Verbose(3) << "Orthovector1: "; 403 402 // Orthovector1.Output(out); … … 426 425 factors[1] = f; 427 426 factors[2] = 0.; 428 FirstOtherAtom->x.LinearCombinationOfVectors( &InBondvector, &Orthovector1, &Orthovector2, factors);427 FirstOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 429 428 factors[1] = -0.5*f; 430 429 factors[2] = g; 431 SecondOtherAtom->x.LinearCombinationOfVectors( &InBondvector, &Orthovector1, &Orthovector2, factors);430 SecondOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 432 431 factors[2] = -g; 433 ThirdOtherAtom->x.LinearCombinationOfVectors( &InBondvector, &Orthovector1, &Orthovector2, factors);432 ThirdOtherAtom->x.LinearCombinationOfVectors(InBondvector, Orthovector1, Orthovector2, factors); 434 433 435 434 // rescale each to correct BondDistance … … 439 438 440 439 // and relative to *origin atom 441 FirstOtherAtom->x .AddVector(&TopOrigin->x);442 SecondOtherAtom->x .AddVector(&TopOrigin->x);443 ThirdOtherAtom->x .AddVector(&TopOrigin->x);440 FirstOtherAtom->x += TopOrigin->x; 441 SecondOtherAtom->x += TopOrigin->x; 442 ThirdOtherAtom->x += TopOrigin->x; 444 443 445 444 // ... and add to molecule … … 1022 1021 Log() << Verbose(5) << "Center of Gravity: " << CenterOfGravity << endl; 1023 1022 Log() << Verbose(5) << "Other Center of Gravity: " << OtherCenterOfGravity << endl; 1024 if (CenterOfGravity.DistanceSquared( &OtherCenterOfGravity) > threshold*threshold) {1023 if (CenterOfGravity.DistanceSquared(OtherCenterOfGravity) > threshold*threshold) { 1025 1024 Log() << Verbose(4) << "Centers of gravity don't match." << endl; 1026 1025 result = false; -
src/molecule.hpp
r72e7fa r273382 145 145 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T), T t ) const; 146 146 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T) const, T t ) const; 147 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T&), T &t ) const; 148 template <typename res, typename T> void ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const; 147 149 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const; 148 150 template <typename res, typename T, typename U> void ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const; -
src/molecule_dynamics.cpp
r72e7fa r273382 39 39 // determine normalized trajectories direction vector (n1, n2) 40 40 Sprinter = Params.PermutationMap[Walker->nr]; // find first target point 41 trajectory1.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); 42 trajectory1.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); 41 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); 43 42 trajectory1.Normalize(); 44 43 Norm1 = trajectory1.Norm(); 45 44 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 46 trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); 47 trajectory2.SubtractVector(&Runner->Trajectory.R.at(Params.startstep)); 45 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep); 48 46 trajectory2.Normalize(); 49 47 Norm2 = trajectory1.Norm(); 50 48 // check whether either is zero() 51 49 if ((Norm1 < MYEPSILON) && (Norm2 < MYEPSILON)) { 52 tmp = Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.startstep));50 tmp = Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.startstep)); 53 51 } else if (Norm1 < MYEPSILON) { 54 52 Sprinter = Params.PermutationMap[Walker->nr]; // find first target point 55 trajectory1.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); // copy first offset 56 trajectory1.SubtractVector(&Runner->Trajectory.R.at(Params.startstep)); // subtract second offset 57 trajectory2.Scale( trajectory1.ScalarProduct(&trajectory2) ); // trajectory2 is scaled to unity, hence we don't need to divide by anything 58 trajectory1.SubtractVector(&trajectory2); // project the part in norm direction away 53 trajectory1 = Sprinter->Trajectory.R.at(Params.endstep) - Runner->Trajectory.R.at(Params.startstep); 54 trajectory2 *= trajectory1.ScalarProduct(trajectory2); // trajectory2 is scaled to unity, hence we don't need to divide by anything 55 trajectory1 -= trajectory2; // project the part in norm direction away 59 56 tmp = trajectory1.Norm(); // remaining norm is distance 60 57 } else if (Norm2 < MYEPSILON) { 61 58 Sprinter = Params.PermutationMap[Runner->nr]; // find second target point 62 trajectory2.CopyVector(&Sprinter->Trajectory.R.at(Params.endstep)); // copy second offset 63 trajectory2.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); // subtract first offset 64 trajectory1.Scale( trajectory2.ScalarProduct(&trajectory1) ); // trajectory1 is scaled to unity, hence we don't need to divide by anything 65 trajectory2.SubtractVector(&trajectory1); // project the part in norm direction away 59 trajectory2 = Sprinter->Trajectory.R.at(Params.endstep) - Walker->Trajectory.R.at(Params.startstep); // copy second offset 60 trajectory1 *= trajectory2.ScalarProduct(trajectory1); // trajectory1 is scaled to unity, hence we don't need to divide by anything 61 trajectory2 -= trajectory1; // project the part in norm direction away 66 62 tmp = trajectory2.Norm(); // remaining norm is distance 67 } else if ((fabs(trajectory1.ScalarProduct( &trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent63 } else if ((fabs(trajectory1.ScalarProduct(trajectory2)/Norm1/Norm2) - 1.) < MYEPSILON) { // check whether they're linear dependent 68 64 // Log() << Verbose(3) << "Both trajectories of " << *Walker << " and " << *Runner << " are linear dependent: "; 69 65 // Log() << Verbose(0) << trajectory1; 70 66 // Log() << Verbose(0) << " and "; 71 67 // Log() << Verbose(0) << trajectory2; 72 tmp = Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.startstep));68 tmp = Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.startstep)); 73 69 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 74 70 } else { // determine distance by finding minimum distance … … 97 93 // Log() << Verbose(0) << " with distance " << tmp << "." << endl; 98 94 // test whether we really have the intersection (by checking on c_1 and c_2) 99 TestVector.CopyVector(&Runner->Trajectory.R.at(Params.startstep));95 trajectory1.Scale(gsl_vector_get(x,0)); 100 96 trajectory2.Scale(gsl_vector_get(x,1)); 101 TestVector.AddVector(&trajectory2);102 97 normal.Scale(gsl_vector_get(x,2)); 103 TestVector.AddVector(&normal); 104 TestVector.SubtractVector(&Walker->Trajectory.R.at(Params.startstep)); 105 trajectory1.Scale(gsl_vector_get(x,0)); 106 TestVector.SubtractVector(&trajectory1); 98 TestVector = Runner->Trajectory.R.at(Params.startstep) + trajectory2 + normal 99 - (Walker->Trajectory.R.at(Params.startstep) + trajectory1); 107 100 if (TestVector.Norm() < MYEPSILON) { 108 101 // Log() << Verbose(2) << "Test: ok.\tDistance of " << tmp << " is correct." << endl; … … 173 166 // first term: distance to target 174 167 Runner = Params.PermutationMap[Walker->nr]; // find target point 175 tmp = (Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.endstep)));168 tmp = (Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep))); 176 169 tmp *= Params.IsAngstroem ? 1. : 1./AtomicLengthToAngstroem; 177 170 result += Params.PenaltyConstants[0] * tmp; … … 232 225 while(Runner->next != mol->end) { 233 226 Runner = Runner->next; 234 Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance( &Runner->Trajectory.R.at(Params.endstep)), Runner) );227 Params.DistanceList[Walker->nr]->insert( DistancePair(Walker->Trajectory.R.at(Params.startstep).Distance(Runner->Trajectory.R.at(Params.endstep)), Runner) ); 235 228 } 236 229 } -
src/molecule_fragmentation.cpp
r72e7fa r273382 1705 1705 //Log() << Verbose (3) << "Current Walker is: " << *Walker << "." << endl; 1706 1706 ColorList[Walker->nr] = black; // mark as explored 1707 Walker->x .AddVector(&Translationvector); // translate1707 Walker->x += Translationvector; // translate 1708 1708 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 1709 1709 if ((*Runner) != Binder) { -
src/molecule_geometry.cpp
r72e7fa r273382 30 30 31 31 // go through all atoms 32 ActOnAllVectors( &Vector::SubtractVector, Center);32 ActOnAllVectors( &Vector::SubtractVector, *Center); 33 33 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv); 34 34 … … 86 86 // Log() << Verbose(0) << endl; 87 87 min->Scale(-1.); 88 max->AddVector(min);88 (*max) += (*min); 89 89 Translate(min); 90 90 Center.Zero(); … … 109 109 ptr = ptr->next; 110 110 Num++; 111 Center .AddVector(&ptr->x);111 Center += ptr->x; 112 112 } 113 113 Center.Scale(-1./Num); // divide through total number (and sign for direction) … … 133 133 ptr = ptr->next; 134 134 Num += 1.; 135 tmp .CopyVector(&ptr->x);136 a->AddVector(&tmp);135 tmp = ptr->x; 136 (*a) += tmp; 137 137 } 138 138 a->Scale(1./Num); // divide through total mass (and sign for direction) … … 158 158 ptr = ptr->next; 159 159 Num += ptr->type->mass; 160 tmp.CopyVector(&ptr->x); 161 tmp.Scale(ptr->type->mass); // scale by mass 162 a->AddVector(&tmp); 160 tmp = ptr->type->mass * ptr->x; 161 (*a) += tmp; 163 162 } 164 163 a->Scale(-1./Num); // divide through total mass (and sign for direction) … … 186 185 void molecule::CenterAtVector(Vector *newcenter) 187 186 { 188 Center .CopyVector(newcenter);187 Center = *newcenter; 189 188 }; 190 189 … … 215 214 ptr = ptr->next; 216 215 for (int j=0;j<MDSteps;j++) 217 ptr->Trajectory.R.at(j).Translate( trans);218 ptr->x.Translate( trans);216 ptr->Trajectory.R.at(j).Translate(*trans); 217 ptr->x.Translate(*trans); 219 218 } 220 219 }; … … 230 229 231 230 // go through all atoms 232 ActOnAllVectors( &Vector::SubtractVector, trans);231 ActOnAllVectors( &Vector::SubtractVector, *trans); 233 232 ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv); 234 233 … … 243 242 void molecule::Mirror(const Vector *n) 244 243 { 245 ActOnAllVectors( &Vector::Mirror, n );244 ActOnAllVectors( &Vector::Mirror, *n ); 246 245 }; 247 246 … … 266 265 if (Walker->type->Z != 1) { 267 266 #endif 268 Testvector .CopyVector(&Walker->x);267 Testvector = Walker->x; 269 268 Testvector.MatrixMultiplication(inversematrix); 270 269 Translationvector.Zero(); … … 283 282 } 284 283 } 285 Testvector .AddVector(&Translationvector);284 Testvector += Translationvector; 286 285 Testvector.MatrixMultiplication(matrix); 287 Center .AddVector(&Testvector);286 Center += Testvector; 288 287 Log() << Verbose(1) << "vector is: " << Testvector << endl; 289 288 #ifdef ADDHYDROGEN … … 291 290 for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) { 292 291 if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) { 293 Testvector .CopyVector(&(*Runner)->GetOtherAtom(Walker)->x);292 Testvector = (*Runner)->GetOtherAtom(Walker)->x; 294 293 Testvector.MatrixMultiplication(inversematrix); 295 Testvector .AddVector(&Translationvector);294 Testvector += Translationvector; 296 295 Testvector.MatrixMultiplication(matrix); 297 Center .AddVector(&Testvector);296 Center += Testvector; 298 297 Log() << Verbose(1) << "Hydrogen vector is: " << Testvector << endl; 299 298 } … … 329 328 while (ptr->next != end) { 330 329 ptr = ptr->next; 331 Vector x; 332 x.CopyVector(&ptr->x); 330 Vector x = ptr->x; 333 331 //x.SubtractVector(CenterOfGravity); 334 332 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]); … … 381 379 while (ptr->next != end) { 382 380 ptr = ptr->next; 383 Vector x; 384 x.CopyVector(&ptr->x); 381 Vector x = ptr->x; 385 382 //x.SubtractVector(CenterOfGravity); 386 383 InertiaTensor[0] += ptr->type->mass*(x[1]*x[1] + x[2]*x[2]); … … 492 489 ptr = ptr->next; 493 490 if (ptr->type == ((struct lsq_params *)params)->type) { // for specific type 494 c.CopyVector(&ptr->x); // copy vector to temporary one 495 c.SubtractVector(&a); // subtract offset vector 496 t = c.ScalarProduct(&b); // get direction parameter 497 d.CopyVector(&b); // and create vector 498 d.Scale(&t); 499 c.SubtractVector(&d); // ... yielding distance vector 500 res += d.ScalarProduct((const Vector *)&d); // add squared distance 491 c = ptr->x - a; 492 t = c.ScalarProduct(b); // get direction parameter 493 d = t*b; // and create vector 494 c -= d; // ... yielding distance vector 495 res += d.ScalarProduct(d); // add squared distance 501 496 } 502 497 } -
src/molecule_graph.cpp
r72e7fa r273382 165 165 //Log() << Verbose(1) << "Checking distance " << OtherWalker->x.PeriodicDistanceSquared(&(Walker->x), cell_size) << " against typical bond length of " << bonddistance*bonddistance << "." << endl; 166 166 (BG->*minmaxdistance)(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem); 167 const double distance = OtherWalker->x.PeriodicDistanceSquared( &(Walker->x), cell_size);167 const double distance = OtherWalker->x.PeriodicDistanceSquared((Walker->x), cell_size); 168 168 const bool status = (distance <= MaxDistance * MaxDistance) && (distance >= MinDistance * MinDistance); 169 169 if ((OtherWalker->father->nr > Walker->father->nr) && (status)) { // create bond if distance is smaller -
src/molecule_template.hpp
r72e7fa r273382 55 55 } 56 56 }; 57 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&), T &t ) const 58 { 59 atom *Walker = start; 60 while (Walker->next != end) { 61 Walker = Walker->next; 62 ((Walker->node)->*f)(t); 63 } 64 }; 65 template <typename res, typename T> void molecule::ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const 66 { 67 atom *Walker = start; 68 while (Walker->next != end) { 69 Walker = Walker->next; 70 ((Walker->node)->*f)(t); 71 } 72 }; 57 73 // two arguments 58 74 template <typename res, typename T, typename U> void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const -
src/moleculelist.cpp
r72e7fa r273382 161 161 Walker = Walker->next; 162 162 counts[Walker->type->getNumber()]++; 163 if (Walker->x.DistanceSquared( &Origin) > size)164 size = Walker->x.DistanceSquared( &Origin);163 if (Walker->x.DistanceSquared(Origin) > size) 164 size = Walker->x.DistanceSquared(Origin); 165 165 } 166 166 // output Index, Name, number of atoms, chemical formula … … 501 501 if ((Runner->type->Z == 1) && (Runner->nr > Walker->nr) && (Binder->GetOtherAtom(Runner) != Binder->GetOtherAtom(Walker))) { // (hydrogens have only one bonding partner!) 502 502 // 4. evaluate the morse potential for each matrix component and add up 503 distance = Runner->x.Distance( &Walker->x);503 distance = Runner->x.Distance(Walker->x); 504 504 //Log() << Verbose(0) << "Fragment " << (*ListRunner)->name << ": " << *Runner << "<= " << distance << "=>" << *Walker << ":" << endl; 505 505 for (int k = 0; k < a; k++) { -
src/tesselation.cpp
r72e7fa r273382 234 234 // have a normal vector on the base line pointing outwards 235 235 //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl; 236 BaseLineCenter.CopyVector(endpoints[0]->node->node); 237 BaseLineCenter.AddVector(endpoints[1]->node->node); 238 BaseLineCenter.Scale(1./2.); 239 BaseLine.CopyVector(endpoints[0]->node->node); 240 BaseLine.SubtractVector(endpoints[1]->node->node); 236 BaseLineCenter = (1./2.)*((*endpoints[0]->node->node) + (*endpoints[1]->node->node)); 237 BaseLine = (*endpoints[0]->node->node) - (*endpoints[1]->node->node); 241 238 //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl; 242 239 … … 248 245 for(TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 249 246 //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 250 NormalCheck .AddVector(&runner->second->NormalVector);251 NormalCheck .Scale(sign);247 NormalCheck += runner->second->NormalVector; 248 NormalCheck *= sign; 252 249 sign = -sign; 253 250 if (runner->second->NormalVector.NormSquared() > MYEPSILON) 254 BaseLineNormal .CopyVector(&runner->second->NormalVector); // yes, copy second on top of first251 BaseLineNormal = runner->second->NormalVector; // yes, copy second on top of first 255 252 else { 256 253 eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl; … … 259 256 if (node != NULL) { 260 257 //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl; 261 helper[i].CopyVector(node->node->node); 262 helper[i].SubtractVector(&BaseLineCenter); 258 helper[i] = (*node->node->node) - BaseLineCenter; 263 259 helper[i].MakeNormalTo(BaseLine); // we want to compare the triangle's heights' angles! 264 260 //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; … … 410 406 411 407 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 412 if (NormalVector.ScalarProduct( &OtherVector) > 0.)408 if (NormalVector.ScalarProduct(OtherVector) > 0.) 413 409 NormalVector.Scale(-1.); 414 410 Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl; … … 446 442 Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl; 447 443 448 if (Intersection->DistanceSquared( endpoints[0]->node->node) < MYEPSILON) {444 if (Intersection->DistanceSquared(*endpoints[0]->node->node) < MYEPSILON) { 449 445 Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl; 450 446 return true; 451 } else if (Intersection->DistanceSquared( endpoints[1]->node->node) < MYEPSILON) {447 } else if (Intersection->DistanceSquared(*endpoints[1]->node->node) < MYEPSILON) { 452 448 Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl; 453 449 return true; 454 } else if (Intersection->DistanceSquared( endpoints[2]->node->node) < MYEPSILON) {450 } else if (Intersection->DistanceSquared(*endpoints[2]->node->node) < MYEPSILON) { 455 451 Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl; 456 452 return true; … … 464 460 *(endpoints[(i+2)%3]->node->node), 465 461 *Intersection); 466 helper.CopyVector(endpoints[(i+1)%3]->node->node); 467 helper.SubtractVector(endpoints[i%3]->node->node); 468 CrossPoint.SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector 469 const double s = CrossPoint.ScalarProduct(&helper)/helper.NormSquared(); 462 helper = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 463 CrossPoint -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 464 const double s = CrossPoint.ScalarProduct(helper)/helper.NormSquared(); 470 465 Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl; 471 466 if ((s < -MYEPSILON) || ((s-1.) > MYEPSILON)) { … … 510 505 } 511 506 catch (LinearDependenceException &excp) { 512 ClosestPoint->CopyVector(x);507 (*ClosestPoint) = (*x); 513 508 } 514 509 515 510 // 2. Calculate in plane part of line (x, intersection) 516 Vector InPlane; 517 InPlane.CopyVector(x); 518 InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point 519 InPlane.ProjectOntoPlane(&NormalVector); 520 InPlane.AddVector(ClosestPoint); 511 Vector InPlane = (*x) - (*ClosestPoint); // points from plane intersection to straight-down point 512 InPlane.ProjectOntoPlane(NormalVector); 513 InPlane += *ClosestPoint; 521 514 522 515 Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl; … … 532 525 for (int i=0;i<3;i++) { 533 526 // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point 534 Direction.CopyVector(endpoints[(i+1)%3]->node->node); 535 Direction.SubtractVector(endpoints[i%3]->node->node); 527 Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 536 528 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 537 529 538 530 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 539 531 540 CrossDirection[i].CopyVector(&CrossPoint[i]); 541 CrossDirection[i].SubtractVector(&InPlane); 542 CrossPoint[i].SubtractVector(endpoints[i%3]->node->node); // cross point was returned as absolute vector 543 const double s = CrossPoint[i].ScalarProduct(&Direction)/Direction.NormSquared(); 532 CrossDirection[i] = CrossPoint[i] - InPlane; 533 CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector 534 const double s = CrossPoint[i].ScalarProduct(Direction)/Direction.NormSquared(); 544 535 Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl; 545 536 if ((s >= -MYEPSILON) && ((s-1.) <= MYEPSILON)) { 546 CrossPoint[i] .AddVector(endpoints[i%3]->node->node); // make cross point absolute again537 CrossPoint[i] += (*endpoints[i%3]->node->node); // make cross point absolute again 547 538 Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i%3]->node->node << " and " << *endpoints[(i+1)%3]->node->node << "." << endl; 548 const double distance = CrossPoint[i].DistanceSquared( x);539 const double distance = CrossPoint[i].DistanceSquared(*x); 549 540 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 550 541 ShortestDistance = distance; 551 ClosestPoint->CopyVector(&CrossPoint[i]);542 (*ClosestPoint) = CrossPoint[i]; 552 543 } 553 544 } else … … 556 547 InsideFlag = true; 557 548 for (int i=0;i<3;i++) { 558 const double sign = CrossDirection[i].ScalarProduct( &CrossDirection[(i+1)%3]);559 const double othersign = CrossDirection[i].ScalarProduct( &CrossDirection[(i+2)%3]);;549 const double sign = CrossDirection[i].ScalarProduct(CrossDirection[(i+1)%3]); 550 const double othersign = CrossDirection[i].ScalarProduct(CrossDirection[(i+2)%3]);; 560 551 if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign 561 552 InsideFlag = false; 562 553 } 563 554 if (InsideFlag) { 564 ClosestPoint->CopyVector(&InPlane);565 ShortestDistance = InPlane.DistanceSquared( x);555 (*ClosestPoint) = InPlane; 556 ShortestDistance = InPlane.DistanceSquared(*x); 566 557 } else { // also check endnodes 567 558 for (int i=0;i<3;i++) { 568 const double distance = x->DistanceSquared( endpoints[i]->node->node);559 const double distance = x->DistanceSquared(*endpoints[i]->node->node); 569 560 if ((ShortestDistance < 0.) || (ShortestDistance > distance)) { 570 561 ShortestDistance = distance; 571 ClosestPoint->CopyVector(endpoints[i]->node->node);562 (*ClosestPoint) = (*endpoints[i]->node->node); 572 563 } 573 564 } … … 687 678 center->Zero(); 688 679 for(int i=0;i<3;i++) 689 center->AddVector(endpoints[i]->node->node);680 (*center) += (*endpoints[i]->node->node); 690 681 center->Scale(1./3.); 691 682 Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl; … … 755 746 for (int i=0;i<3;i++) // increase each of them 756 747 Runner[i]++; 757 TotalNormal->AddVector(&TemporaryNormal);748 (*TotalNormal) += TemporaryNormal; 758 749 } 759 750 TotalNormal->Scale(1./(double)counter); 760 751 761 752 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 762 if (TotalNormal->ScalarProduct( &OtherVector) > 0.)753 if (TotalNormal->ScalarProduct(OtherVector) > 0.) 763 754 TotalNormal->Scale(-1.); 764 755 Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl; … … 777 768 int counter = 0; 778 769 for(PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) { 779 center->AddVector((*Runner)->node->node);770 (*center) += (*(*Runner)->node->node); 780 771 counter++; 781 772 } … … 1028 1019 { 1029 1020 Info FunctionInfo(__func__); 1030 OptCenter .CopyVector(&OptCandidateCenter);1031 OtherOptCenter .CopyVector(&OtherOptCandidateCenter);1021 OptCenter = OptCandidateCenter; 1022 OtherOptCenter = OtherOptCandidateCenter; 1032 1023 }; 1033 1024 … … 1105 1096 int num=0; 1106 1097 for (GoToFirst(); (!IsEnd()); GoToNext()) { 1107 Center->AddVector(GetPoint()->node);1098 (*Center) += (*GetPoint()->node); 1108 1099 num++; 1109 1100 } … … 1217 1208 for (; C != PointsOnBoundary.end(); C++) 1218 1209 { 1219 tmp = A->second->node->node->DistanceSquared( B->second->node->node);1210 tmp = A->second->node->node->DistanceSquared(*B->second->node->node); 1220 1211 distance = tmp * tmp; 1221 tmp = A->second->node->node->DistanceSquared( C->second->node->node);1212 tmp = A->second->node->node->DistanceSquared(*C->second->node->node); 1222 1213 distance += tmp * tmp; 1223 tmp = B->second->node->node->DistanceSquared( C->second->node->node);1214 tmp = B->second->node->node->DistanceSquared(*C->second->node->node); 1224 1215 distance += tmp * tmp; 1225 1216 DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C))); … … 1255 1246 continue; 1256 1247 // 4a. project onto plane vector 1257 TrialVector.CopyVector(checker->second->node->node); 1258 TrialVector.SubtractVector(A->second->node->node); 1259 distance = TrialVector.ScalarProduct(&PlaneVector); 1248 TrialVector = (*checker->second->node->node) - (*A->second->node->node); 1249 distance = TrialVector.ScalarProduct(PlaneVector); 1260 1250 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 1261 1251 continue; … … 1285 1275 } 1286 1276 // 4d. Check whether the point is inside the triangle (check distance to each node 1287 tmp = checker->second->node->node->DistanceSquared( A->second->node->node);1277 tmp = checker->second->node->node->DistanceSquared(*A->second->node->node); 1288 1278 int innerpoint = 0; 1289 1279 if ((tmp < A->second->node->node->DistanceSquared( 1290 baseline->second.first->second->node->node)) && (tmp1280 *baseline->second.first->second->node->node)) && (tmp 1291 1281 < A->second->node->node->DistanceSquared( 1292 baseline->second.second->second->node->node)))1282 *baseline->second.second->second->node->node))) 1293 1283 innerpoint++; 1294 1284 tmp = checker->second->node->node->DistanceSquared( 1295 baseline->second.first->second->node->node);1285 *baseline->second.first->second->node->node); 1296 1286 if ((tmp < baseline->second.first->second->node->node->DistanceSquared( 1297 A->second->node->node)) && (tmp1287 *A->second->node->node)) && (tmp 1298 1288 < baseline->second.first->second->node->node->DistanceSquared( 1299 baseline->second.second->second->node->node)))1289 *baseline->second.second->second->node->node))) 1300 1290 innerpoint++; 1301 1291 tmp = checker->second->node->node->DistanceSquared( 1302 baseline->second.second->second->node->node);1292 *baseline->second.second->second->node->node); 1303 1293 if ((tmp < baseline->second.second->second->node->node->DistanceSquared( 1304 baseline->second.first->second->node->node)) && (tmp1294 *baseline->second.first->second->node->node)) && (tmp 1305 1295 < baseline->second.second->second->node->node->DistanceSquared( 1306 A->second->node->node)))1296 *A->second->node->node))) 1307 1297 innerpoint++; 1308 1298 // 4e. If so, break 4. loop and continue with next candidate in 1. loop … … 1390 1380 // prepare some auxiliary vectors 1391 1381 Vector BaseLineCenter, BaseLine; 1392 BaseLineCenter.CopyVector(baseline->second->endpoints[0]->node->node); 1393 BaseLineCenter.AddVector(baseline->second->endpoints[1]->node->node); 1394 BaseLineCenter.Scale(1. / 2.); // points now to center of base line 1395 BaseLine.CopyVector(baseline->second->endpoints[0]->node->node); 1396 BaseLine.SubtractVector(baseline->second->endpoints[1]->node->node); 1382 BaseLineCenter = 0.5 * ((*baseline->second->endpoints[0]->node->node) + 1383 (*baseline->second->endpoints[1]->node->node)); 1384 BaseLine = (*baseline->second->endpoints[0]->node->node) - (*baseline->second->endpoints[1]->node->node); 1397 1385 1398 1386 // offset to center of triangle 1399 1387 CenterVector.Zero(); 1400 1388 for (int i = 0; i < 3; i++) 1401 CenterVector .AddVector(BTS->endpoints[i]->node->node);1389 CenterVector += (*BTS->endpoints[i]->node->node); 1402 1390 CenterVector.Scale(1. / 3.); 1403 1391 Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl; 1404 1392 1405 1393 // normal vector of triangle 1406 NormalVector.CopyVector(Center); 1407 NormalVector.SubtractVector(&CenterVector); 1394 NormalVector = (*Center) - CenterVector; 1408 1395 BTS->GetNormalVector(NormalVector); 1409 NormalVector .CopyVector(&BTS->NormalVector);1396 NormalVector = BTS->NormalVector; 1410 1397 Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl; 1411 1398 … … 1413 1400 // project center vector onto triangle plane (points from intersection plane-NormalVector to plane-CenterVector intersection) 1414 1401 PropagationVector = Plane(BaseLine, NormalVector,0).getNormal(); 1415 TempVector.CopyVector(&CenterVector); 1416 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1402 TempVector = CenterVector - (*baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 1417 1403 //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl; 1418 if (PropagationVector.ScalarProduct( &TempVector) > 0) // make sure normal propagation vector points outward from baseline1404 if (PropagationVector.ScalarProduct(TempVector) > 0) // make sure normal propagation vector points outward from baseline 1419 1405 PropagationVector.Scale(-1.); 1420 1406 Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl; … … 1427 1413 1428 1414 // first check direction, so that triangles don't intersect 1429 VirtualNormalVector.CopyVector(target->second->node->node); 1430 VirtualNormalVector.SubtractVector(&BaseLineCenter); // points from center of base line to target 1431 VirtualNormalVector.ProjectOntoPlane(&NormalVector); 1432 TempAngle = VirtualNormalVector.Angle(&PropagationVector); 1415 VirtualNormalVector = (*target->second->node->node) - BaseLineCenter; 1416 TempAngle = VirtualNormalVector.Angle(PropagationVector); 1433 1417 Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl; 1434 1418 if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees) … … 1457 1441 1458 1442 // check for linear dependence 1459 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1460 TempVector.SubtractVector(target->second->node->node); 1461 helper.CopyVector(baseline->second->endpoints[1]->node->node); 1462 helper.SubtractVector(target->second->node->node); 1463 helper.ProjectOntoPlane(&TempVector); 1443 TempVector = (*baseline->second->endpoints[0]->node->node) - (*target->second->node->node); 1444 helper = (*baseline->second->endpoints[1]->node->node) - (*target->second->node->node); 1445 helper.ProjectOntoPlane(TempVector); 1464 1446 if (fabs(helper.NormSquared()) < MYEPSILON) { 1465 1447 Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl; … … 1472 1454 *(baseline->second->endpoints[1]->node->node), 1473 1455 *(target->second->node->node)).getNormal(); 1474 TempVector.CopyVector(baseline->second->endpoints[0]->node->node); 1475 TempVector.AddVector(baseline->second->endpoints[1]->node->node); 1476 TempVector.AddVector(target->second->node->node); 1477 TempVector.Scale(1./3.); 1478 TempVector.SubtractVector(Center); 1456 TempVector = (1./3.) * ((*baseline->second->endpoints[0]->node->node) + 1457 (*baseline->second->endpoints[1]->node->node) + 1458 (*target->second->node->node)); 1459 TempVector -= (*Center); 1479 1460 // make it always point outward 1480 if (VirtualNormalVector.ScalarProduct( &TempVector) < 0)1461 if (VirtualNormalVector.ScalarProduct(TempVector) < 0) 1481 1462 VirtualNormalVector.Scale(-1.); 1482 1463 // calculate angle 1483 TempAngle = NormalVector.Angle( &VirtualNormalVector);1464 TempAngle = NormalVector.Angle(VirtualNormalVector); 1484 1465 Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl; 1485 1466 if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner … … 1489 1470 } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle) 1490 1471 // hence, check the angles to some normal direction from our base line but in this common plane of both targets... 1491 helper.CopyVector(target->second->node->node); 1492 helper.SubtractVector(&BaseLineCenter); 1493 helper.ProjectOntoPlane(&BaseLine); 1472 helper = (*target->second->node->node) - BaseLineCenter; 1473 helper.ProjectOntoPlane(BaseLine); 1494 1474 // ...the one with the smaller angle is the better candidate 1495 TempVector.CopyVector(target->second->node->node); 1496 TempVector.SubtractVector(&BaseLineCenter); 1497 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1498 TempAngle = TempVector.Angle(&helper); 1499 TempVector.CopyVector(winner->second->node->node); 1500 TempVector.SubtractVector(&BaseLineCenter); 1501 TempVector.ProjectOntoPlane(&VirtualNormalVector); 1502 if (TempAngle < TempVector.Angle(&helper)) { 1503 TempAngle = NormalVector.Angle(&VirtualNormalVector); 1475 TempVector = (*target->second->node->node) - BaseLineCenter; 1476 TempVector.ProjectOntoPlane(VirtualNormalVector); 1477 TempAngle = TempVector.Angle(helper); 1478 TempVector = (*winner->second->node->node) - BaseLineCenter; 1479 TempVector.ProjectOntoPlane(VirtualNormalVector); 1480 if (TempAngle < TempVector.Angle(helper)) { 1481 TempAngle = NormalVector.Angle(VirtualNormalVector); 1504 1482 SmallestAngle = TempAngle; 1505 1483 winner = target; … … 1538 1516 BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount); 1539 1517 BTS->GetCenter(&helper); 1540 helper .SubtractVector(Center);1541 helper .Scale(-1);1518 helper -= (*Center); 1519 helper *= -1; 1542 1520 BTS->GetNormalVector(helper); 1543 1521 TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS)); … … 1596 1574 Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl; 1597 1575 // we have the intersection, check whether in- or outside of boundary 1598 if ((Center->DistanceSquared( Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {1576 if ((Center->DistanceSquared(*Walker->node) - Center->DistanceSquared(Intersection)) < -MYEPSILON) { 1599 1577 // inside, next! 1600 1578 Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl; … … 1609 1587 OldPoints[i] = BTS->endpoints[i]; 1610 1588 } 1611 Normal .CopyVector(&BTS->NormalVector);1589 Normal = BTS->NormalVector; 1612 1590 // add Walker to boundary points 1613 1591 Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl; … … 2119 2097 2120 2098 // construct center of circle 2121 CircleCenter.CopyVector(BaseLine.endpoints[0]->node->node); 2122 CircleCenter.AddVector(BaseLine.endpoints[1]->node->node); 2123 CircleCenter.Scale(0.5); 2099 CircleCenter = 0.5 * ((*BaseLine.endpoints[0]->node->node) + (*BaseLine.endpoints[1]->node->node)); 2124 2100 2125 2101 // construct normal vector of circle 2126 CirclePlaneNormal.CopyVector(BaseLine.endpoints[0]->node->node); 2127 CirclePlaneNormal.SubtractVector(BaseLine.endpoints[1]->node->node); 2102 CirclePlaneNormal = (*BaseLine.endpoints[0]->node->node) - (*BaseLine.endpoints[1]->node->node); 2128 2103 2129 2104 double radius = CirclePlaneNormal.NormSquared(); 2130 2105 double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.); 2131 2106 2132 NormalVector.ProjectOntoPlane( &CirclePlaneNormal);2107 NormalVector.ProjectOntoPlane(CirclePlaneNormal); 2133 2108 NormalVector.Normalize(); 2134 2109 ShortestAngle = 2.*M_PI; // This will indicate the quadrant. 2135 2110 2136 SphereCenter.CopyVector(&NormalVector); 2137 SphereCenter.Scale(CircleRadius); 2138 SphereCenter.AddVector(&CircleCenter); 2111 SphereCenter = (CircleRadius * NormalVector) + CircleCenter; 2139 2112 // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized) 2140 2113 … … 2337 2310 2338 2311 // construct center of circle 2339 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2340 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2341 CircleCenter.Scale(0.5); 2312 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 2313 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 2342 2314 2343 2315 // construct normal vector of circle 2344 CirclePlaneNormal .CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);2345 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);2316 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 2317 (*CandidateLine.BaseLine->endpoints[1]->node->node); 2346 2318 2347 2319 // calculate squared radius of circle 2348 radius = CirclePlaneNormal.ScalarProduct( &CirclePlaneNormal);2320 radius = CirclePlaneNormal.ScalarProduct(CirclePlaneNormal); 2349 2321 if (radius/4. < RADIUS*RADIUS) { 2350 2322 // construct relative sphere center with now known CircleCenter 2351 RelativeSphereCenter.CopyVector(&T.SphereCenter); 2352 RelativeSphereCenter.SubtractVector(&CircleCenter); 2323 RelativeSphereCenter = T.SphereCenter - CircleCenter; 2353 2324 2354 2325 CircleRadius = RADIUS*RADIUS - radius/4.; … … 2360 2331 // construct SearchDirection and an "outward pointer" 2361 2332 SearchDirection = Plane(RelativeSphereCenter, CirclePlaneNormal,0).getNormal(); 2362 helper.CopyVector(&CircleCenter); 2363 helper.SubtractVector(ThirdNode->node); 2364 if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2333 helper = CircleCenter - (*ThirdNode->node); 2334 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards! 2365 2335 SearchDirection.Scale(-1.); 2366 2336 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 2367 if (fabs(RelativeSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) {2337 if (fabs(RelativeSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { 2368 2338 // rotated the wrong way! 2369 2339 eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl; … … 2512 2482 AddTesselationTriangle(); 2513 2483 BTS->GetCenter(&Center); 2514 Center .SubtractVector(&CandidateLine.OptCenter);2515 BTS->SphereCenter .CopyVector(&CandidateLine.OptCenter);2484 Center -= CandidateLine.OptCenter; 2485 BTS->SphereCenter = CandidateLine.OptCenter; 2516 2486 BTS->GetNormalVector(Center); 2517 2487 … … 2559 2529 Vector DistanceToIntersection[2], BaseLine; 2560 2530 double distance[2]; 2561 BaseLine.CopyVector(Base->endpoints[1]->node->node); 2562 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 2531 BaseLine = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node); 2563 2532 for (int i=0;i<2;i++) { 2564 DistanceToIntersection[i].CopyVector(ClosestPoint); 2565 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 2566 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 2533 DistanceToIntersection[i] = (*ClosestPoint) - (*Base->endpoints[i]->node->node); 2534 distance[i] = BaseLine.ScalarProduct(DistanceToIntersection[i]); 2567 2535 } 2568 2536 delete(ClosestPoint); … … 2636 2604 2637 2605 // get the distance vector from Base line to OtherBase line 2638 Vector Distance; 2639 Distance.CopyVector(ClosestPoint[1]); 2640 Distance.SubtractVector(ClosestPoint[0]); 2606 Vector Distance = (*ClosestPoint[1]) - (*ClosestPoint[0]); 2641 2607 2642 2608 // calculate volume … … 2660 2626 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2661 2627 Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl; 2662 BaseLineNormal .AddVector(&(runner->second->NormalVector));2628 BaseLineNormal += (runner->second->NormalVector); 2663 2629 } 2664 2630 BaseLineNormal.Scale(1./2.); 2665 2631 2666 if (Distance.ScalarProduct( &BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip2632 if (Distance.ScalarProduct(BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip 2667 2633 Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl; 2668 2634 // calculate volume summand as a general tetraeder … … 2699 2665 for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) { 2700 2666 Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl; 2701 BaseLineNormal .AddVector(&(runner->second->NormalVector));2667 BaseLineNormal += (runner->second->NormalVector); 2702 2668 } 2703 2669 BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector() … … 2840 2806 double distance, scaleFactor; 2841 2807 2842 OrthogonalizedOben.CopyVector(&Oben); 2843 aCandidate.CopyVector(a->node); 2844 aCandidate.SubtractVector(Candidate->node); 2845 OrthogonalizedOben.ProjectOntoPlane(&aCandidate); 2808 OrthogonalizedOben = Oben; 2809 aCandidate = (*a->node) - (*Candidate->node); 2810 OrthogonalizedOben.ProjectOntoPlane(aCandidate); 2846 2811 OrthogonalizedOben.Normalize(); 2847 2812 distance = 0.5 * aCandidate.Norm(); … … 2849 2814 OrthogonalizedOben.Scale(scaleFactor); 2850 2815 2851 Center.CopyVector(Candidate->node); 2852 Center.AddVector(a->node); 2853 Center.Scale(0.5); 2854 Center.AddVector(&OrthogonalizedOben); 2855 2856 AngleCheck.CopyVector(&Center); 2857 AngleCheck.SubtractVector(a->node); 2816 Center = 0.5 * ((*Candidate->node) + (*a->node)); 2817 Center += OrthogonalizedOben; 2818 2819 AngleCheck = Center - (*a->node); 2858 2820 norm = aCandidate.Norm(); 2859 2821 // second point shall have smallest angle with respect to Oben vector 2860 2822 if (norm < RADIUS*2.) { 2861 angle = AngleCheck.Angle( &Oben);2823 angle = AngleCheck.Angle(Oben); 2862 2824 if (angle < Storage[0]) { 2863 2825 //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]); … … 2935 2897 2936 2898 // construct center of circle 2937 CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2938 CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2939 CircleCenter.Scale(0.5); 2899 CircleCenter = 0.5 * ((*CandidateLine.BaseLine->endpoints[0]->node->node) + 2900 (*CandidateLine.BaseLine->endpoints[1]->node->node)); 2940 2901 2941 2902 // construct normal vector of circle 2942 CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node); 2943 CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node); 2944 2945 RelativeOldSphereCenter.CopyVector(&OldSphereCenter); 2946 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 2903 CirclePlaneNormal = (*CandidateLine.BaseLine->endpoints[0]->node->node) - 2904 (*CandidateLine.BaseLine->endpoints[1]->node->node); 2905 2906 RelativeOldSphereCenter = OldSphereCenter - CircleCenter; 2947 2907 2948 2908 // calculate squared radius TesselPoint *ThirdNode,f circle … … 2954 2914 2955 2915 // test whether old center is on the band's plane 2956 if (fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) > HULLEPSILON) {2957 eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct( &CirclePlaneNormal)) << "!" << endl;2958 RelativeOldSphereCenter.ProjectOntoPlane( &CirclePlaneNormal);2916 if (fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) { 2917 eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(CirclePlaneNormal)) << "!" << endl; 2918 RelativeOldSphereCenter.ProjectOntoPlane(CirclePlaneNormal); 2959 2919 } 2960 2920 radius = RelativeOldSphereCenter.NormSquared(); … … 2964 2924 // check SearchDirection 2965 2925 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 2966 if (fabs(RelativeOldSphereCenter.ScalarProduct( &SearchDirection)) > HULLEPSILON) { // rotated the wrong way!2926 if (fabs(RelativeOldSphereCenter.ScalarProduct(SearchDirection)) > HULLEPSILON) { // rotated the wrong way! 2967 2927 eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl; 2968 2928 } … … 3011 2971 3012 2972 Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl; 3013 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared( &NewPlaneCenter);2973 radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(NewPlaneCenter); 3014 2974 Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl; 3015 2975 Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl; 3016 2976 Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl; 3017 2977 if (radius < RADIUS*RADIUS) { 3018 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared( &NewPlaneCenter);2978 otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(NewPlaneCenter); 3019 2979 if (fabs(radius - otherradius) > HULLEPSILON) { 3020 2980 eLog() << Verbose(1) << "Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius-otherradius) << endl; 3021 2981 } 3022 2982 // construct both new centers 3023 NewSphereCenter.CopyVector(&NewPlaneCenter); 3024 OtherNewSphereCenter.CopyVector(&NewPlaneCenter); 3025 helper.CopyVector(&NewNormalVector); 3026 helper.Scale(sqrt(RADIUS*RADIUS - radius)); 2983 NewSphereCenter = NewPlaneCenter; 2984 OtherNewSphereCenter = NewPlaneCenter; 2985 helper = sqrt(RADIUS*RADIUS - radius) * NewNormalVector; 3027 2986 Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl; 3028 NewSphereCenter .AddVector(&helper);2987 NewSphereCenter += helper; 3029 2988 Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl; 3030 2989 // OtherNewSphereCenter is created by the same vector just in the other direction 3031 2990 helper.Scale(-1.); 3032 OtherNewSphereCenter .AddVector(&helper);2991 OtherNewSphereCenter += helper; 3033 2992 Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl; 3034 2993 … … 3041 3000 if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) { 3042 3001 if (fabs(alpha - Otheralpha) > MYEPSILON) { 3043 CandidateLine.OptCenter .CopyVector(&NewSphereCenter);3044 CandidateLine.OtherOptCenter .CopyVector(&OtherNewSphereCenter);3002 CandidateLine.OptCenter = NewSphereCenter; 3003 CandidateLine.OtherOptCenter = OtherNewSphereCenter; 3045 3004 } else { 3046 CandidateLine.OptCenter .CopyVector(&OtherNewSphereCenter);3047 CandidateLine.OtherOptCenter .CopyVector(&NewSphereCenter);3005 CandidateLine.OptCenter = OtherNewSphereCenter; 3006 CandidateLine.OtherOptCenter = NewSphereCenter; 3048 3007 } 3049 3008 // if there is an equal candidate, add it to the list without clearing the list … … 3168 3127 FindPoint = PointsOnBoundary.find((*Runner)->nr); 3169 3128 if (FindPoint != PointsOnBoundary.end()) { 3170 points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared( x), FindPoint->second) );3129 points->insert(DistanceToPointPair (FindPoint->second->node->node->DistanceSquared(*x), FindPoint->second) ); 3171 3130 Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl; 3172 3131 } … … 3212 3171 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3213 3172 // calculate closest point on line to desired point 3214 helper.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3215 helper.AddVector((LineRunner->second)->endpoints[1]->node->node); 3216 helper.Scale(0.5); 3217 Center.CopyVector(x); 3218 Center.SubtractVector(&helper); 3219 BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node); 3220 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3221 Center.ProjectOntoPlane(&BaseLine); 3173 helper = 0.5 * ((*(LineRunner->second)->endpoints[0]->node->node) + 3174 (*(LineRunner->second)->endpoints[1]->node->node)); 3175 Center = (*x) - helper; 3176 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3177 (*(LineRunner->second)->endpoints[1]->node->node); 3178 Center.ProjectOntoPlane(BaseLine); 3222 3179 const double distance = Center.NormSquared(); 3223 3180 if ((ClosestLine == NULL) || (distance < MinDistance)) { 3224 3181 // additionally calculate intersection on line (whether it's on the line section or not) 3225 helper.CopyVector(x); 3226 helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3227 helper.SubtractVector(&Center); 3228 const double lengthA = helper.ScalarProduct(&BaseLine); 3229 helper.CopyVector(x); 3230 helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3231 helper.SubtractVector(&Center); 3232 const double lengthB = helper.ScalarProduct(&BaseLine); 3182 helper = (*x) - (*(LineRunner->second)->endpoints[0]->node->node) - Center; 3183 const double lengthA = helper.ScalarProduct(BaseLine); 3184 helper = (*x) - (*(LineRunner->second)->endpoints[1]->node->node) - Center; 3185 const double lengthB = helper.ScalarProduct(BaseLine); 3233 3186 if (lengthB*lengthA < 0) { // if have different sign 3234 3187 ClosestLine = LineRunner->second; … … 3280 3233 for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) { 3281 3234 3282 BaseLine .CopyVector((LineRunner->second)->endpoints[0]->node->node);3283 BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);3235 BaseLine = (*(LineRunner->second)->endpoints[0]->node->node) - 3236 (*(LineRunner->second)->endpoints[1]->node->node); 3284 3237 const double lengthBase = BaseLine.NormSquared(); 3285 3238 3286 BaseLineIntersection.CopyVector(x); 3287 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node); 3239 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[0]->node->node); 3288 3240 const double lengthEndA = BaseLineIntersection.NormSquared(); 3289 3241 3290 BaseLineIntersection.CopyVector(x); 3291 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3242 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3292 3243 const double lengthEndB = BaseLineIntersection.NormSquared(); 3293 3244 … … 3307 3258 } else { // intersection is closer, calculate 3308 3259 // calculate closest point on line to desired point 3309 BaseLineIntersection.CopyVector(x); 3310 BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node); 3311 Center.CopyVector(&BaseLineIntersection); 3312 Center.ProjectOntoPlane(&BaseLine); 3313 BaseLineIntersection.SubtractVector(&Center); 3260 BaseLineIntersection = (*x) - (*(LineRunner->second)->endpoints[1]->node->node); 3261 Center = BaseLineIntersection; 3262 Center.ProjectOntoPlane(BaseLine); 3263 BaseLineIntersection -= Center; 3314 3264 const double distance = BaseLineIntersection.NormSquared(); 3315 3265 if (Center.NormSquared() > BaseLine.NormSquared()) { … … 3363 3313 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) { 3364 3314 (*Runner)->GetCenter(&Center); 3365 helper.CopyVector(x); 3366 helper.SubtractVector(&Center); 3367 const double Alignment = helper.Angle(&(*Runner)->NormalVector); 3315 helper = (*x) - Center; 3316 const double Alignment = helper.Angle((*Runner)->NormalVector); 3368 3317 if (Alignment < MinAlignment) { 3369 3318 result = *Runner; … … 3427 3376 triangle->GetCenter(&Center); 3428 3377 Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl; 3429 DistanceToCenter.CopyVector(&Center); 3430 DistanceToCenter.SubtractVector(&Point); 3378 DistanceToCenter = Center - Point; 3431 3379 Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl; 3432 3380 3433 3381 // check whether we are on boundary 3434 if (fabs(DistanceToCenter.ScalarProduct( &triangle->NormalVector)) < MYEPSILON) {3382 if (fabs(DistanceToCenter.ScalarProduct(triangle->NormalVector)) < MYEPSILON) { 3435 3383 // calculate whether inside of triangle 3436 DistanceToCenter.CopyVector(&Point); 3437 Center.CopyVector(&Point); 3438 Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter 3439 DistanceToCenter.AddVector(&triangle->NormalVector); // points outside 3384 DistanceToCenter = Point + triangle->NormalVector; // points outside 3385 Center = Point - triangle->NormalVector; // points towards MolCenter 3440 3386 Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl; 3441 3387 if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) { … … 3452 3398 3453 3399 // then check direction to boundary 3454 if (DistanceToCenter.ScalarProduct( &triangle->NormalVector) > MYEPSILON) {3400 if (DistanceToCenter.ScalarProduct(triangle->NormalVector) > MYEPSILON) { 3455 3401 Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl; 3456 3402 return -distance; … … 3568 3514 if ((triangles != NULL) && (!triangles->empty())) { 3569 3515 for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) 3570 PlaneNormal .AddVector(&(*Runner)->NormalVector);3516 PlaneNormal += (*Runner)->NormalVector; 3571 3517 } else { 3572 3518 eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl; … … 3579 3525 // construct one orthogonal vector 3580 3526 if (Reference != NULL) { 3581 AngleZero.CopyVector(Reference); 3582 AngleZero.SubtractVector(Point->node); 3583 AngleZero.ProjectOntoPlane(&PlaneNormal); 3527 AngleZero = (*Reference) - (*Point->node); 3528 AngleZero.ProjectOntoPlane(PlaneNormal); 3584 3529 } 3585 3530 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) { 3586 3531 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl; 3587 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3588 AngleZero.SubtractVector(Point->node); 3589 AngleZero.ProjectOntoPlane(&PlaneNormal); 3532 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3533 AngleZero.ProjectOntoPlane(PlaneNormal); 3590 3534 if (AngleZero.NormSquared() < MYEPSILON) { 3591 3535 eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl; … … 3602 3546 // go through all connected points and calculate angle 3603 3547 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3604 helper.CopyVector((*listRunner)->node); 3605 helper.SubtractVector(Point->node); 3606 helper.ProjectOntoPlane(&PlaneNormal); 3548 helper = (*(*listRunner)->node) - (*Point->node); 3549 helper.ProjectOntoPlane(PlaneNormal); 3607 3550 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3608 3551 Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl; … … 3671 3614 TesselB++; 3672 3615 TesselC++; 3673 PlaneNormal .AddVector(&helper);3616 PlaneNormal += helper; 3674 3617 } 3675 3618 //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size() … … 3686 3629 // construct one orthogonal vector 3687 3630 if (Reference != NULL) { 3688 AngleZero.CopyVector(Reference); 3689 AngleZero.SubtractVector(Point->node); 3690 AngleZero.ProjectOntoPlane(&PlaneNormal); 3631 AngleZero = (*Reference) - (*Point->node); 3632 AngleZero.ProjectOntoPlane(PlaneNormal); 3691 3633 } 3692 3634 if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) { 3693 3635 Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl; 3694 AngleZero.CopyVector((*SetOfNeighbours->begin())->node); 3695 AngleZero.SubtractVector(Point->node); 3696 AngleZero.ProjectOntoPlane(&PlaneNormal); 3636 AngleZero = (*(*SetOfNeighbours->begin())->node) - (*Point->node); 3637 AngleZero.ProjectOntoPlane(PlaneNormal); 3697 3638 if (AngleZero.NormSquared() < MYEPSILON) { 3698 3639 eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl; … … 3710 3651 pair <map<double, TesselPoint*>::iterator, bool > InserterTest; 3711 3652 for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) { 3712 helper.CopyVector((*listRunner)->node); 3713 helper.SubtractVector(Point->node); 3714 helper.ProjectOntoPlane(&PlaneNormal); 3653 helper = (*(*listRunner)->node) - (*Point->node); 3654 helper.ProjectOntoPlane(PlaneNormal); 3715 3655 double angle = GetAngle(helper, AngleZero, OrthogonalVector); 3716 3656 if (angle > M_PI) // the correction is of no use here (and not desired) … … 3959 3899 3960 3900 // copy old location for the volume 3961 OldPoint .CopyVector(point->node->node);3901 OldPoint = (*point->node->node); 3962 3902 3963 3903 // get list of connected points … … 3987 3927 for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) { 3988 3928 Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl; 3989 NormalVector .SubtractVector(&Runner->second->NormalVector); // has to point inward3929 NormalVector -= Runner->second->NormalVector; // has to point inward 3990 3930 RemoveTesselationTriangle(Runner->second); 3991 3931 count++; … … 4023 3963 StartNode--; 4024 3964 //Log() << Verbose(3) << "INFO: StartNode is " << **StartNode << "." << endl; 4025 Point.CopyVector((*StartNode)->node); 4026 Point.SubtractVector((*MiddleNode)->node); 3965 Point = (*(*StartNode)->node) - (*(*MiddleNode)->node); 4027 3966 StartNode = MiddleNode; 4028 3967 StartNode++; … … 4030 3969 StartNode = connectedPath->begin(); 4031 3970 //Log() << Verbose(3) << "INFO: EndNode is " << **StartNode << "." << endl; 4032 Reference.CopyVector((*StartNode)->node); 4033 Reference.SubtractVector((*MiddleNode)->node); 4034 OrthogonalVector.CopyVector((*MiddleNode)->node); 4035 OrthogonalVector.SubtractVector(&OldPoint); 3971 Reference = (*(*StartNode)->node) - (*(*MiddleNode)->node); 3972 OrthogonalVector = (*(*MiddleNode)->node) - OldPoint; 4036 3973 OrthogonalVector.MakeNormalTo(Reference); 4037 3974 angle = GetAngle(Point, Reference, OrthogonalVector); … … 4502 4439 class BoundaryLineSet *BestLine = NULL; 4503 4440 for (LineMap::iterator Runner = NearestBoundaryPoint->lines.begin(); Runner != NearestBoundaryPoint->lines.end(); Runner++) { 4504 BaseLine.CopyVector(Runner->second->endpoints[0]->node->node); 4505 BaseLine.SubtractVector(Runner->second->endpoints[1]->node->node); 4506 CenterToPoint.CopyVector(Runner->second->endpoints[0]->node->node); 4507 CenterToPoint.AddVector(Runner->second->endpoints[1]->node->node); 4508 CenterToPoint.Scale(0.5); 4509 CenterToPoint.SubtractVector(point->node); 4510 angle = CenterToPoint.Angle(&BaseLine); 4441 BaseLine = (*Runner->second->endpoints[0]->node->node) - 4442 (*Runner->second->endpoints[1]->node->node); 4443 CenterToPoint = 0.5 * ((*Runner->second->endpoints[0]->node->node) + 4444 (*Runner->second->endpoints[1]->node->node)); 4445 CenterToPoint -= (*point->node); 4446 angle = CenterToPoint.Angle(BaseLine); 4511 4447 if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) { 4512 4448 BestAngle = angle; … … 4672 4608 for (map < int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++) 4673 4609 if (VectorWalker != VectorRunner) { // skip equals 4674 const double SCP = VectorWalker->second->ScalarProduct( VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles4610 const double SCP = VectorWalker->second->ScalarProduct(*VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles 4675 4611 Log() << Verbose(1) << "Checking " << *VectorWalker->second<< " against " << *VectorRunner->second << ": " << SCP << endl; 4676 4612 if (fabs(SCP + 1.) < ParallelEpsilon) { … … 4758 4694 TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator 4759 4695 /// 4a. Get NormalVector for one side (this is "front") 4760 NormalVector .CopyVector(&(*TriangleWalker)->NormalVector);4696 NormalVector = (*TriangleWalker)->NormalVector; 4761 4697 Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl; 4762 4698 TriangleWalker++; … … 4769 4705 TriangleSprinter++; 4770 4706 Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl; 4771 if (triangle->NormalVector.ScalarProduct( &NormalVector) < 0) { // if from other side, then delete and remove from list4707 if (triangle->NormalVector.ScalarProduct(NormalVector) < 0) { // if from other side, then delete and remove from list 4772 4708 Log() << Verbose(1) << " Removing ... " << endl; 4773 4709 TriangleNrs.push(triangle->Nr); … … 4791 4727 AddTesselationTriangle(); // ... and add 4792 4728 TriangleNrs.pop(); 4793 BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector); 4794 BTS->NormalVector.Scale(-1.); 4729 BTS->NormalVector = -1 * (*TriangleWalker)->NormalVector; 4795 4730 TriangleWalker++; 4796 4731 } -
src/tesselationhelpers.cpp
r72e7fa r273382 88 88 center->at(2) = 0.5 * m14/ m11; 89 89 90 if (fabs(a.Distance( center) - RADIUS) > MYEPSILON)91 eLog() << Verbose(1) << "The given center is further way by " << fabs(a.Distance( center) - RADIUS) << " from a than RADIUS." << endl;90 if (fabs(a.Distance(*center) - RADIUS) > MYEPSILON) 91 eLog() << Verbose(1) << "The given center is further way by " << fabs(a.Distance(*center) - RADIUS) << " from a than RADIUS." << endl; 92 92 93 93 gsl_matrix_free(A); … … 121 121 Vector OtherCenter; 122 122 Center->Zero(); 123 helper.CopyVector(&a); 124 helper.Scale(sin(2.*alpha)); 125 Center->AddVector(&helper); 126 helper.CopyVector(&b); 127 helper.Scale(sin(2.*beta)); 128 Center->AddVector(&helper); 129 helper.CopyVector(&c); 130 helper.Scale(sin(2.*gamma)); 131 Center->AddVector(&helper); 123 helper = sin(2.*alpha) * a; 124 (*Center) += helper; 125 helper = sin(2.*beta) * b; 126 (*Center) += helper; 127 helper = sin(2.*gamma) * c; 128 (*Center) += helper; 132 129 //*Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ; 133 130 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma))); 134 NewUmkreismittelpunkt->CopyVector(Center);131 (*NewUmkreismittelpunkt) = (*Center); 135 132 Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n"; 136 133 // Here we calculated center of circumscribing circle, using barycentric coordinates 137 134 Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n"; 138 135 139 TempNormal.CopyVector(&a); 140 TempNormal.SubtractVector(&b); 141 helper.CopyVector(&a); 142 helper.SubtractVector(&c); 143 TempNormal.VectorProduct(&helper); 136 TempNormal = a - b; 137 helper = a - c; 138 TempNormal.VectorProduct(helper); 144 139 if (fabs(HalfplaneIndicator) < MYEPSILON) 145 140 { 146 if ((TempNormal.ScalarProduct( AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(AlternativeDirection) >0 && AlternativeIndicator <0))141 if ((TempNormal.ScalarProduct(*AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(*AlternativeDirection) >0 && AlternativeIndicator <0)) 147 142 { 148 TempNormal .Scale(-1);143 TempNormal *= -1; 149 144 } 150 145 } 151 146 else 152 147 { 153 if (((TempNormal.ScalarProduct( Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(Direction)>0) && (HalfplaneIndicator<0)))148 if (((TempNormal.ScalarProduct(*Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(*Direction)>0) && (HalfplaneIndicator<0))) 154 149 { 155 TempNormal .Scale(-1);150 TempNormal *= -1; 156 151 } 157 152 } … … 163 158 Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n"; 164 159 165 Center->AddVector(&TempNormal);160 (*Center) += TempNormal; 166 161 Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n"; 167 162 GetSphere(&OtherCenter, a, b, c, RADIUS); … … 181 176 Vector helper; 182 177 double alpha, beta, gamma; 183 Vector SideA, SideB, SideC; 184 SideA.CopyVector(b); 185 SideA.SubtractVector(&c); 186 SideB.CopyVector(c); 187 SideB.SubtractVector(&a); 188 SideC.CopyVector(a); 189 SideC.SubtractVector(&b); 190 alpha = M_PI - SideB.Angle(&SideC); 191 beta = M_PI - SideC.Angle(&SideA); 192 gamma = M_PI - SideA.Angle(&SideB); 178 Vector SideA = b - c; 179 Vector SideB = c - a; 180 Vector SideC = a - b; 181 alpha = M_PI - SideB.Angle(SideC); 182 beta = M_PI - SideC.Angle(SideA); 183 gamma = M_PI - SideA.Angle(SideB); 193 184 //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl; 194 185 if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) { … … 197 188 198 189 Center->Zero(); 199 helper.CopyVector(a); 200 helper.Scale(sin(2.*alpha)); 201 Center->AddVector(&helper); 202 helper.CopyVector(b); 203 helper.Scale(sin(2.*beta)); 204 Center->AddVector(&helper); 205 helper.CopyVector(c); 206 helper.Scale(sin(2.*gamma)); 207 Center->AddVector(&helper); 190 helper = sin(2.*alpha) * a; 191 (*Center) += helper; 192 helper = sin(2.*beta) * b; 193 (*Center) += helper; 194 helper = sin(2.*gamma) * c; 195 (*Center) += helper; 208 196 Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma))); 209 197 }; … … 227 215 Vector helper; 228 216 double radius, alpha; 229 Vector RelativeOldSphereCenter; 230 Vector RelativeNewSphereCenter; 231 232 RelativeOldSphereCenter.CopyVector(&OldSphereCenter); 233 RelativeOldSphereCenter.SubtractVector(&CircleCenter); 234 RelativeNewSphereCenter.CopyVector(&NewSphereCenter); 235 RelativeNewSphereCenter.SubtractVector(&CircleCenter); 236 helper.CopyVector(&RelativeNewSphereCenter); 217 218 Vector RelativeOldSphereCenter = OldSphereCenter - CircleCenter; 219 Vector RelativeNewSphereCenter = NewSphereCenter - CircleCenter; 220 helper = RelativeNewSphereCenter; 237 221 // test whether new center is on the parameter circle's plane 238 if (fabs(helper.ScalarProduct( &CirclePlaneNormal)) > HULLEPSILON) {239 eLog() << Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct( &CirclePlaneNormal)) << "!" << endl;240 helper.ProjectOntoPlane( &CirclePlaneNormal);222 if (fabs(helper.ScalarProduct(CirclePlaneNormal)) > HULLEPSILON) { 223 eLog() << Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(CirclePlaneNormal)) << "!" << endl; 224 helper.ProjectOntoPlane(CirclePlaneNormal); 241 225 } 242 226 radius = helper.NormSquared(); … … 244 228 if (fabs(radius - CircleRadius) > HULLEPSILON) 245 229 eLog() << Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl; 246 alpha = helper.Angle( &RelativeOldSphereCenter);230 alpha = helper.Angle(RelativeOldSphereCenter); 247 231 // make the angle unique by checking the halfplanes/search direction 248 if (helper.ScalarProduct( &SearchDirection) < -HULLEPSILON) // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals232 if (helper.ScalarProduct(SearchDirection) < -HULLEPSILON) // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals 249 233 alpha = 2.*M_PI - alpha; 250 234 Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl; 251 radius = helper.Distance( &RelativeOldSphereCenter);252 helper.ProjectOntoPlane( &NormalVector);235 radius = helper.Distance(RelativeOldSphereCenter); 236 helper.ProjectOntoPlane(NormalVector); 253 237 // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles 254 238 if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) { … … 280 264 struct Intersection *I = (struct Intersection *)params; 281 265 Vector intersection; 282 Vector SideA,SideB,HeightA, HeightB;283 266 for (int i=0;i<NDIM;i++) 284 267 intersection[i] = gsl_vector_get(x, i); 285 268 286 SideA.CopyVector(&(I->x1)); 287 SideA.SubtractVector(&I->x2); 288 HeightA.CopyVector(&intersection); 289 HeightA.SubtractVector(&I->x1); 290 HeightA.ProjectOntoPlane(&SideA); 291 292 SideB.CopyVector(&I->x3); 293 SideB.SubtractVector(&I->x4); 294 HeightB.CopyVector(&intersection); 295 HeightB.SubtractVector(&I->x3); 296 HeightB.ProjectOntoPlane(&SideB); 297 298 retval = HeightA.ScalarProduct(&HeightA) + HeightB.ScalarProduct(&HeightB); 269 Vector SideA = I->x1 -I->x2 ; 270 Vector HeightA = intersection - I->x1; 271 HeightA.ProjectOntoPlane(SideA); 272 273 Vector SideB = I->x3 - I->x4; 274 Vector HeightB = intersection - I->x3; 275 HeightB.ProjectOntoPlane(SideB); 276 277 retval = HeightA.ScalarProduct(HeightA) + HeightB.ScalarProduct(HeightB); 299 278 //Log() << Verbose(1) << "MinIntersectDistance called, result: " << retval << endl; 300 279 … … 321 300 322 301 struct Intersection par; 323 par.x1 .CopyVector(&point1);324 par.x2 .CopyVector(&point2);325 par.x3 .CopyVector(&point3);326 par.x4 .CopyVector(&point4);302 par.x1 = point1; 303 par.x2 = point2; 304 par.x3 = point3; 305 par.x4 = point4; 327 306 328 307 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; … … 370 349 371 350 // check whether intersection is in between or not 372 Vector intersection , SideA, SideB, HeightA, HeightB;351 Vector intersection; 373 352 double t1, t2; 374 353 for (int i = 0; i < NDIM; i++) { … … 376 355 } 377 356 378 SideA.CopyVector(&par.x2); 379 SideA.SubtractVector(&par.x1); 380 HeightA.CopyVector(&intersection); 381 HeightA.SubtractVector(&par.x1); 382 383 t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA); 384 385 SideB.CopyVector(&par.x4); 386 SideB.SubtractVector(&par.x3); 387 HeightB.CopyVector(&intersection); 388 HeightB.SubtractVector(&par.x3); 389 390 t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB); 357 Vector SideA = par.x2 - par.x1; 358 Vector HeightA = intersection - par.x1; 359 360 t1 = HeightA.ScalarProduct(SideA)/SideA.ScalarProduct(SideA); 361 362 Vector SideB = par.x4 - par.x3; 363 Vector HeightB = intersection - par.x3; 364 365 t2 = HeightB.ScalarProduct(SideB)/SideB.ScalarProduct(SideB); 391 366 392 367 Log() << Verbose(1) << "Intersection " << intersection << " is at " … … 428 403 if (point.IsZero()) 429 404 return M_PI; 430 double phi = point.Angle( &reference);431 if (OrthogonalVector.ScalarProduct( &point) > 0) {405 double phi = point.Angle(reference); 406 if (OrthogonalVector.ScalarProduct(point) > 0) { 432 407 phi = 2.*M_PI - phi; 433 408 } … … 456 431 TetraederVector[2].CopyVector(c); 457 432 for (int j=0;j<3;j++) 458 TetraederVector[j].SubtractVector( &d);459 Point.CopyVector( &TetraederVector[0]);460 Point.VectorProduct( &TetraederVector[1]);461 volume = 1./6. * fabs(Point.ScalarProduct( &TetraederVector[2]));433 TetraederVector[j].SubtractVector(d); 434 Point.CopyVector(TetraederVector[0]); 435 Point.VectorProduct(TetraederVector[1]); 436 volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2])); 462 437 return volume; 463 438 }; … … 583 558 if (List != NULL) { 584 559 for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 585 helper.CopyVector(Point); 586 helper.SubtractVector((*Runner)->node); 587 double currentNorm = helper. Norm(); 560 helper = (*Point) - (*(*Runner)->node); 561 double currentNorm = helper.Norm(); 588 562 if (currentNorm < distance) { 589 563 // remember second point … … 638 612 if (List != NULL) { 639 613 for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) { 640 helper.CopyVector(Point); 641 helper.SubtractVector((*Runner)->node); 614 helper = (*Point) - (*(*Runner)->node); 642 615 double currentNorm = helper.NormSquared(); 643 616 if (currentNorm < distance) { … … 678 651 Info FunctionInfo(__func__); 679 652 // construct the plane of the two baselines (i.e. take both their directional vectors) 680 Vector Normal; 681 Vector Baseline, OtherBaseline; 682 Baseline.CopyVector(Base->endpoints[1]->node->node); 683 Baseline.SubtractVector(Base->endpoints[0]->node->node); 684 OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node); 685 OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node); 686 Normal.CopyVector(&Baseline); 687 Normal.VectorProduct(&OtherBaseline); 653 Vector Baseline = (*Base->endpoints[1]->node->node) - (*Base->endpoints[0]->node->node); 654 Vector OtherBaseline = (*OtherBase->endpoints[1]->node->node) - (*OtherBase->endpoints[0]->node->node); 655 Vector Normal = Baseline; 656 Normal.VectorProduct(OtherBaseline); 688 657 Normal.Normalize(); 689 658 Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl; 690 659 691 660 // project one offset point of OtherBase onto this plane (and add plane offset vector) 692 Vector NewOffset; 693 NewOffset.CopyVector(OtherBase->endpoints[0]->node->node); 694 NewOffset.SubtractVector(Base->endpoints[0]->node->node); 695 NewOffset.ProjectOntoPlane(&Normal); 696 NewOffset.AddVector(Base->endpoints[0]->node->node); 697 Vector NewDirection; 698 NewDirection.CopyVector(&NewOffset); 699 NewDirection.AddVector(&OtherBaseline); 661 Vector NewOffset = (*OtherBase->endpoints[0]->node->node) - (*Base->endpoints[0]->node->node); 662 NewOffset.ProjectOntoPlane(Normal); 663 NewOffset += (*Base->endpoints[0]->node->node); 664 Vector NewDirection = NewOffset + OtherBaseline; 700 665 701 666 // calculate the intersection between this projected baseline and Base … … 704 669 *(Base->endpoints[1]->node->node), 705 670 NewOffset, NewDirection); 706 Normal.CopyVector(Intersection); 707 Normal.SubtractVector(Base->endpoints[0]->node->node); 708 Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl; 671 Normal = (*Intersection) - (*Base->endpoints[0]->node->node); 672 Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(Baseline)/Baseline.NormSquared()) << "." << endl; 709 673 710 674 return Intersection; … … 724 688 return -1; 725 689 } 726 distance = x->DistanceToPlane( &triangle->NormalVector,triangle->endpoints[0]->node->node);690 distance = x->DistanceToPlane(triangle->NormalVector, *triangle->endpoints[0]->node->node); 727 691 return distance; 728 692 }; … … 787 751 Vector *center = cloud->GetCenter(); 788 752 // make the circumsphere's center absolute again 789 helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node); 790 helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node); 791 helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node); 792 helper.Scale(1./3.); 793 helper.SubtractVector(center); 753 Vector helper = (1./3.) * ((*Tess->LastTriangle->endpoints[0]->node->node) + 754 (*Tess->LastTriangle->endpoints[1]->node->node) + 755 (*Tess->LastTriangle->endpoints[2]->node->node)); 756 helper -= (*center); 794 757 // and add to file plus translucency object 795 758 *rasterfile << "# current virtual sphere\n"; -
src/test/ActOnAlltest.hpp
r72e7fa r273382 27 27 28 28 template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T), T t ); 29 template <typename klasse, typename res, typename T> void ActOnAll( res (klasse::*f)(T&), T &t ); 29 30 template <typename klasse, typename res, typename T, typename U> void ActOnAll( res (klasse::*f)(T, U), T t, U u ); 30 31 template <typename klasse, typename res, typename T, typename U, typename V> void ActOnAll( res (klasse::*f)(T, U, V), T t, U u, V v); … … 76 77 }; 77 78 79 template <typename klasse, typename res, typename T> void VectorList::ActOnAll( res (klasse::*f)(T&), T &t ) 80 { 81 for (ListOfVectors::iterator Runner = Vectors.begin(); Runner != Vectors.end(); Runner++) 82 ((*Runner)->*f)(t); 83 }; 84 78 85 template <typename klasse, typename res, typename T, typename U> void VectorList::ActOnAll( res (klasse::*f)(T, U), T t, U u ) 79 86 { -
src/unittests/ActOnAllUnitTest.cpp
r72e7fa r273382 56 56 57 57 // adding, subtracting 58 VL.ActOnAll( &Vector::AddVector, &test );58 VL.ActOnAll( &Vector::AddVector, test ); 59 59 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 60 VL.ActOnAll( &Vector::SubtractVector, &test );60 VL.ActOnAll( &Vector::SubtractVector, test ); 61 61 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 62 62 }; -
src/unittests/vectorunittest.cpp
r72e7fa r273382 72 72 CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture ); 73 73 // summation and scaling 74 fixture.CopyVector(&zero); 75 fixture.AddVector(&unit); 76 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 77 fixture.CopyVector(&zero); 78 fixture.SubtractVector(&unit); 74 fixture = zero + unit; 75 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 76 fixture = zero - unit; 79 77 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 80 78 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 81 fixture.CopyVector(&zero); 82 fixture.AddVector(&zero); 79 fixture = zero + zero; 83 80 CPPUNIT_ASSERT_EQUAL( true, fixture.IsZero() ); 84 fixture.CopyVector(¬unit); 85 fixture.SubtractVector(&otherunit); 86 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 87 fixture.CopyVector(&unit); 88 fixture.AddVector(&otherunit); 81 fixture = notunit - otherunit; 82 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 83 fixture = unit - otherunit; 89 84 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 90 fixture.CopyVector(¬unit); 91 fixture.SubtractVector(&unit); 92 fixture.SubtractVector(&otherunit); 85 fixture = notunit - unit - otherunit; 93 86 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 94 fixture.CopyVector(&unit); 95 fixture.Scale(0.98); 87 fixture = 0.98 * unit; 96 88 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 97 fixture.CopyVector(&unit); 98 fixture.Scale(1.); 99 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 100 fixture.CopyVector(&unit); 89 fixture = 1. * unit; 90 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 101 91 factor = 0.98; 102 fixture .Scale(factor);92 fixture = factor * unit; 103 93 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 104 fixture.CopyVector(&unit);105 94 factor = 1.; 106 fixture .Scale(factor);95 fixture = factor * unit; 107 96 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 108 97 }; … … 134 123 void VectorTest::EuclidianScalarProductTest() 135 124 { 136 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &zero) );137 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &unit) );138 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( &otherunit) );139 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct( ¬unit) );140 CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct( &unit) );141 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct( &unit) );142 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct( &unit) );143 CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct( ¬unit) );144 CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct( &unit) );145 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct( &otherunit) );146 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct( ¬unit) );125 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(zero) ); 126 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(unit) ); 127 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(otherunit) ); 128 CPPUNIT_ASSERT_EQUAL( 0., zero.ScalarProduct(notunit) ); 129 CPPUNIT_ASSERT_EQUAL( 1., unit.ScalarProduct(unit) ); 130 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) ); 131 CPPUNIT_ASSERT_EQUAL( 0., otherunit.ScalarProduct(unit) ); 132 CPPUNIT_ASSERT_EQUAL( 1., otherunit.ScalarProduct(notunit) ); 133 CPPUNIT_ASSERT_EQUAL( 2., two.ScalarProduct(unit) ); 134 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(otherunit) ); 135 CPPUNIT_ASSERT_EQUAL( 1., two.ScalarProduct(notunit) ); 147 136 } 148 137 … … 165 154 void VectorTest::EuclidianDistancesTest() 166 155 { 167 CPPUNIT_ASSERT_EQUAL( 1., zero.Distance( &unit) );168 CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance( &unit) );169 CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance( ¬unit) );170 CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance( ¬unit) );171 CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance( ¬unit) );156 CPPUNIT_ASSERT_EQUAL( 1., zero.Distance(unit) ); 157 CPPUNIT_ASSERT_EQUAL( sqrt(2.), otherunit.Distance(unit) ); 158 CPPUNIT_ASSERT_EQUAL( sqrt(2.), zero.Distance(notunit) ); 159 CPPUNIT_ASSERT_EQUAL( 1., otherunit.Distance(notunit) ); 160 CPPUNIT_ASSERT_EQUAL( sqrt(5.), two.Distance(notunit) ); 172 161 } 173 162 … … 176 165 void VectorTest::EuclidianAnglesTest() 177 166 { 178 CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle( &unit) );179 CPPUNIT_ASSERT_EQUAL( 0., unit.Angle( &unit) );180 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle( &unit)) < MYEPSILON );181 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle( ¬unit)) < MYEPSILON );182 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle( ¬unit)) < MYEPSILON );167 CPPUNIT_ASSERT_EQUAL( M_PI, zero.Angle(unit) ); 168 CPPUNIT_ASSERT_EQUAL( 0., unit.Angle(unit) ); 169 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - otherunit.Angle(unit)) < MYEPSILON ); 170 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/2. - unit.Angle(notunit)) < MYEPSILON ); 171 CPPUNIT_ASSERT_EQUAL( true, fabs(M_PI/4. - otherunit.Angle(notunit)) < MYEPSILON ); 183 172 }; 184 173 … … 187 176 void VectorTest::ProjectionTest() 188 177 { 189 CPPUNIT_ASSERT_EQUAL( zero, zero.Projection( &unit) );190 CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection( &unit) );191 CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.), otherunit.Projection( &two) );192 CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.), two.Projection( &otherunit) );178 CPPUNIT_ASSERT_EQUAL( zero, zero.Projection(unit) ); 179 CPPUNIT_ASSERT_EQUAL( zero, otherunit.Projection(unit) ); 180 CPPUNIT_ASSERT_EQUAL( Vector(0.4,0.2,0.), otherunit.Projection(two) ); 181 CPPUNIT_ASSERT_EQUAL( Vector(0.,1.,0.), two.Projection(otherunit) ); 193 182 }; 194 183 -
src/vector.cpp
r72e7fa r273382 70 70 * \return \f$| x - y |^2\f$ 71 71 */ 72 double Vector::DistanceSquared(const Vector * consty) const72 double Vector::DistanceSquared(const Vector &y) const 73 73 { 74 74 double res = 0.; 75 75 for (int i=NDIM;i--;) 76 res += (x[i]-y ->x[i])*(x[i]-y->x[i]);76 res += (x[i]-y[i])*(x[i]-y[i]); 77 77 return (res); 78 78 }; … … 82 82 * \return \f$| x - y |\f$ 83 83 */ 84 double Vector::Distance(const Vector * const y) const 85 { 86 double res = 0.; 87 for (int i=NDIM;i--;) 88 res += (x[i]-y->x[i])*(x[i]-y->x[i]); 89 return (sqrt(res)); 84 double Vector::Distance(const Vector &y) const 85 { 86 return (sqrt(DistanceSquared(y))); 90 87 }; 91 88 … … 95 92 * \return \f$| x - y |\f$ 96 93 */ 97 double Vector::PeriodicDistance(const Vector * consty, const double * const cell_size) const94 double Vector::PeriodicDistance(const Vector &y, const double * const cell_size) const 98 95 { 99 96 double res = Distance(y), tmp, matrix[NDIM*NDIM]; … … 119 116 TranslationVector.MatrixMultiplication(matrix); 120 117 // add onto the original vector to compare with 121 Shiftedy.CopyVector(y); 122 Shiftedy.AddVector(&TranslationVector); 118 Shiftedy = y + TranslationVector; 123 119 // get distance and compare with minimum so far 124 tmp = Distance( &Shiftedy);120 tmp = Distance(Shiftedy); 125 121 if (tmp < res) res = tmp; 126 122 } … … 133 129 * \return \f$| x - y |^2\f$ 134 130 */ 135 double Vector::PeriodicDistanceSquared(const Vector * consty, const double * const cell_size) const131 double Vector::PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const 136 132 { 137 133 double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM]; … … 157 153 TranslationVector.MatrixMultiplication(matrix); 158 154 // add onto the original vector to compare with 159 Shiftedy.CopyVector(y); 160 Shiftedy.AddVector(&TranslationVector); 155 Shiftedy = y + TranslationVector; 161 156 // get distance and compare with minimum so far 162 tmp = DistanceSquared( &Shiftedy);157 tmp = DistanceSquared(Shiftedy); 163 158 if (tmp < res) res = tmp; 164 159 } … … 180 175 // Output(out); 181 176 // Log() << Verbose(0) << endl; 182 TestVector .CopyVector(this);177 TestVector = (*this); 183 178 TestVector.InverseMatrixMultiplication(matrix); 184 179 for(int i=NDIM;i--;) { // correct periodically … … 190 185 } 191 186 TestVector.MatrixMultiplication(matrix); 192 CopyVector(&TestVector);187 (*this) = TestVector; 193 188 // Log() << Verbose(2) << "New corrected vector is: "; 194 189 // Output(out); … … 201 196 * \return \f$\langle x, y \rangle\f$ 202 197 */ 203 double Vector::ScalarProduct(const Vector * consty) const198 double Vector::ScalarProduct(const Vector &y) const 204 199 { 205 200 double res = 0.; 206 201 for (int i=NDIM;i--;) 207 res += x[i]*y ->x[i];202 res += x[i]*y[i]; 208 203 return (res); 209 204 }; … … 216 211 * \return \f$ x \times y \f& 217 212 */ 218 void Vector::VectorProduct(const Vector * consty)213 void Vector::VectorProduct(const Vector &y) 219 214 { 220 215 Vector tmp; 221 tmp .x[0] = x[1]* (y->x[2]) - x[2]* (y->x[1]);222 tmp .x[1] = x[2]* (y->x[0]) - x[0]* (y->x[2]);223 tmp .x[2] = x[0]* (y->x[1]) - x[1]* (y->x[0]);224 this->CopyVector(&tmp);216 tmp[0] = x[1]* (y[2]) - x[2]* (y[1]); 217 tmp[1] = x[2]* (y[0]) - x[0]* (y[2]); 218 tmp[2] = x[0]* (y[1]) - x[1]* (y[0]); 219 (*this) = tmp; 225 220 }; 226 221 … … 230 225 * \return \f$\langle x, y \rangle\f$ 231 226 */ 232 void Vector::ProjectOntoPlane(const Vector * const y) 233 { 234 Vector tmp; 235 tmp.CopyVector(y); 227 void Vector::ProjectOntoPlane(const Vector &y) 228 { 229 Vector tmp = y; 236 230 tmp.Normalize(); 237 tmp .Scale(ScalarProduct(&tmp));238 this->SubtractVector(&tmp);231 tmp *= ScalarProduct(tmp); 232 (*this) -= tmp; 239 233 }; 240 234 … … 245 239 * \return distance to plane 246 240 */ 247 double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const 248 { 249 Vector temp; 250 241 double Vector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const 242 { 251 243 // first create part that is orthonormal to PlaneNormal with withdraw 252 temp.CopyVector(this); 253 temp.SubtractVector(PlaneOffset); 254 temp.MakeNormalTo(*PlaneNormal); 255 temp.Scale(-1.); 244 Vector temp = (*this) - PlaneOffset; 245 temp.MakeNormalTo(PlaneNormal); 246 temp *= -1.; 256 247 // then add connecting vector from plane to point 257 temp .AddVector(this);258 temp .SubtractVector(PlaneOffset);248 temp += (*this); 249 temp -= PlaneOffset; 259 250 double sign = temp.ScalarProduct(PlaneNormal); 260 251 if (fabs(sign) > MYEPSILON) … … 269 260 * \param *y array to second vector 270 261 */ 271 void Vector::ProjectIt(const Vector * consty)272 { 273 Vector helper (*y);262 void Vector::ProjectIt(const Vector &y) 263 { 264 Vector helper = y; 274 265 helper.Scale(-(ScalarProduct(y))); 275 AddVector( &helper);266 AddVector(helper); 276 267 }; 277 268 … … 280 271 * \return Vector 281 272 */ 282 Vector Vector::Projection(const Vector * consty) const283 { 284 Vector helper (*y);285 helper.Scale((ScalarProduct(y)/y ->NormSquared()));273 Vector Vector::Projection(const Vector &y) const 274 { 275 Vector helper = y; 276 helper.Scale((ScalarProduct(y)/y.NormSquared())); 286 277 287 278 return helper; … … 293 284 double Vector::Norm() const 294 285 { 295 double res = 0.; 296 for (int i=NDIM;i--;) 297 res += this->x[i]*this->x[i]; 298 return (sqrt(res)); 286 return (sqrt(NormSquared())); 299 287 }; 300 288 … … 304 292 double Vector::NormSquared() const 305 293 { 306 return (ScalarProduct( this));294 return (ScalarProduct(*this)); 307 295 }; 308 296 … … 363 351 * @return true - vector is normalized, false - vector is not 364 352 */ 365 bool Vector::IsNormalTo(const Vector * constnormal) const353 bool Vector::IsNormalTo(const Vector &normal) const 366 354 { 367 355 if (ScalarProduct(normal) < MYEPSILON) … … 374 362 * @return true - vector is normalized, false - vector is not 375 363 */ 376 bool Vector::IsEqualTo(const Vector * consta) const364 bool Vector::IsEqualTo(const Vector &a) const 377 365 { 378 366 bool status = true; 379 367 for (int i=0;i<NDIM;i++) { 380 if (fabs(x[i] - a ->x[i]) > MYEPSILON)368 if (fabs(x[i] - a[i]) > MYEPSILON) 381 369 status = false; 382 370 } … … 388 376 * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$ 389 377 */ 390 double Vector::Angle(const Vector * consty) const391 { 392 double norm1 = Norm(), norm2 = y ->Norm();378 double Vector::Angle(const Vector &y) const 379 { 380 double norm1 = Norm(), norm2 = y.Norm(); 393 381 double angle = -1; 394 382 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) … … 446 434 const Vector& Vector::operator+=(const Vector& b) 447 435 { 448 this->AddVector( &b);436 this->AddVector(b); 449 437 return *this; 450 438 }; … … 457 445 const Vector& Vector::operator-=(const Vector& b) 458 446 { 459 this->SubtractVector( &b);447 this->SubtractVector(b); 460 448 return *this; 461 449 }; … … 480 468 { 481 469 Vector x = *this; 482 x.AddVector( &b);470 x.AddVector(b); 483 471 return x; 484 472 }; … … 492 480 { 493 481 Vector x = *this; 494 x.SubtractVector( &b);482 x.SubtractVector(b); 495 483 return x; 496 484 }; … … 556 544 * \param trans[] translation vector. 557 545 */ 558 void Vector::Translate(const Vector * consttrans)559 { 560 for (int i=NDIM;i--;) 561 x[i] += trans ->x[i];546 void Vector::Translate(const Vector &trans) 547 { 548 for (int i=NDIM;i--;) 549 x[i] += trans[i]; 562 550 }; 563 551 … … 639 627 * \param *factors three-component vector with the factor for each given vector 640 628 */ 641 void Vector::LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors) 642 { 643 for(int i=NDIM;i--;) 644 x[i] = factors[0]*x1->x[i] + factors[1]*x2->x[i] + factors[2]*x3->x[i]; 629 void Vector::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors) 630 { 631 (*this) = (factors[0]*x1) + 632 (factors[1]*x2) + 633 (factors[2]*x3); 645 634 }; 646 635 … … 648 637 * \param n[] normal vector of mirror plane. 649 638 */ 650 void Vector::Mirror(const Vector * constn)639 void Vector::Mirror(const Vector &n) 651 640 { 652 641 double projection; 653 projection = ScalarProduct(n)/n ->ScalarProduct(n); // remove constancy from n (keep as logical one)642 projection = ScalarProduct(n)/n.NormSquared(); // remove constancy from n (keep as logical one) 654 643 // withdraw projected vector twice from original one 655 644 for (int i=NDIM;i--;) 656 x[i] -= 2.*projection*n ->x[i];645 x[i] -= 2.*projection*n[i]; 657 646 }; 658 647 … … 667 656 { 668 657 bool result = false; 669 double factor = y1.ScalarProduct(this)/y1.NormSquared(); 670 Vector x1; 671 x1.CopyVector(&y1); 672 x1.Scale(factor); 673 SubtractVector(&x1); 658 double factor = y1.ScalarProduct(*this)/y1.NormSquared(); 659 Vector x1 = factor * y1 ; 660 SubtractVector(x1); 674 661 for (int i=NDIM;i--;) 675 662 result = result || (fabs(x[i]) > MYEPSILON); … … 684 671 * \return true - success, false - failure (null vector given) 685 672 */ 686 bool Vector::GetOneNormalVector(const Vector * constGivenVector)673 bool Vector::GetOneNormalVector(const Vector &GivenVector) 687 674 { 688 675 int Components[NDIM]; // contains indices of non-zero components … … 695 682 // find two components != 0 696 683 for (j=0;j<NDIM;j++) 697 if (fabs(GivenVector ->x[j]) > MYEPSILON)684 if (fabs(GivenVector[j]) > MYEPSILON) 698 685 Components[Last++] = j; 699 686 … … 701 688 case 3: // threecomponent system 702 689 case 2: // two component system 703 norm = sqrt(1./(GivenVector ->x[Components[1]]*GivenVector->x[Components[1]]) + 1./(GivenVector->x[Components[0]]*GivenVector->x[Components[0]]));690 norm = sqrt(1./(GivenVector[Components[1]]*GivenVector[Components[1]]) + 1./(GivenVector[Components[0]]*GivenVector[Components[0]])); 704 691 x[Components[2]] = 0.; 705 692 // in skp both remaining parts shall become zero but with opposite sign and third is zero 706 x[Components[1]] = -1./GivenVector ->x[Components[1]] / norm;707 x[Components[0]] = 1./GivenVector ->x[Components[0]] / norm;693 x[Components[1]] = -1./GivenVector[Components[1]] / norm; 694 x[Components[0]] = 1./GivenVector[Components[0]] / norm; 708 695 return true; 709 696 break; … … 720 707 }; 721 708 722 /** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.723 * \param *A first plane vector724 * \param *B second plane vector725 * \param *C third plane vector726 * \return scaling parameter for this vector727 */728 double Vector::CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const729 {730 // Log() << Verbose(3) << "For comparison: ";731 // Log() << Verbose(0) << "A " << A->Projection(this) << "\t";732 // Log() << Verbose(0) << "B " << B->Projection(this) << "\t";733 // Log() << Verbose(0) << "C " << C->Projection(this) << "\t";734 // Log() << Verbose(0) << endl;735 return A->ScalarProduct(this);736 };737 738 739 709 /** Adds vector \a *y componentwise. 740 710 * \param *y vector 741 711 */ 742 void Vector::AddVector(const Vector * consty)743 { 744 for (int i=NDIM;i--;) 745 this->x[i] += y ->x[i];712 void Vector::AddVector(const Vector &y) 713 { 714 for (int i=NDIM;i--;) 715 this->x[i] += y[i]; 746 716 } 747 717 … … 749 719 * \param *y vector 750 720 */ 751 void Vector::SubtractVector(const Vector * const y) 752 { 753 for (int i=NDIM;i--;) 754 this->x[i] -= y->x[i]; 755 } 756 757 /** Copy vector \a *y componentwise. 758 * \param *y vector 759 */ 760 void Vector::CopyVector(const Vector * const y) 761 { 762 // check for self assignment 763 if(y!=this){ 764 for (int i=NDIM;i--;) 765 this->x[i] = y->x[i]; 766 } 721 void Vector::SubtractVector(const Vector &y) 722 { 723 for (int i=NDIM;i--;) 724 this->x[i] -= y[i]; 767 725 } 768 726 … … 964 922 bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 965 923 { 966 Vector a; 967 a.CopyVector(this); 968 a.SubtractVector(&offset); 924 Vector a = (*this) - offset; 969 925 a.InverseMatrixMultiplication(parallelepiped); 970 926 bool isInside = true; -
src/vector.hpp
r72e7fa r273382 33 33 virtual ~Vector(); 34 34 35 virtual double Distance(const Vector * consty) const;36 virtual double DistanceSquared(const Vector * consty) const;37 virtual double DistanceToPlane(const Vector * const PlaneNormal, const Vector * constPlaneOffset) const;38 virtual double PeriodicDistance(const Vector * consty, const double * const cell_size) const;39 virtual double PeriodicDistanceSquared(const Vector * consty, const double * const cell_size) const;40 virtual double ScalarProduct(const Vector * consty) const;35 virtual double Distance(const Vector &y) const; 36 virtual double DistanceSquared(const Vector &y) const; 37 virtual double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const; 38 virtual double PeriodicDistance(const Vector &y, const double * const cell_size) const; 39 virtual double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const; 40 virtual double ScalarProduct(const Vector &y) const; 41 41 virtual double Norm() const; 42 42 virtual double NormSquared() const; 43 virtual double Angle(const Vector * consty) const;43 virtual double Angle(const Vector &y) const; 44 44 virtual bool IsZero() const; 45 45 virtual bool IsOne() const; 46 virtual bool IsNormalTo(const Vector * constnormal) const;47 virtual bool IsEqualTo(const Vector * consta) const;46 virtual bool IsNormalTo(const Vector &normal) const; 47 virtual bool IsEqualTo(const Vector &a) const; 48 48 49 virtual void AddVector(const Vector * const y); 50 virtual void SubtractVector(const Vector * const y); 51 virtual void CopyVector(const Vector * const y); 49 virtual void AddVector(const Vector &y); 50 virtual void SubtractVector(const Vector &y); 52 51 virtual void CopyVector(const Vector &y); 53 virtual void VectorProduct(const Vector * consty);54 virtual void ProjectOntoPlane(const Vector * consty);55 virtual void ProjectIt(const Vector * consty);56 virtual Vector Projection(const Vector * consty) const;52 virtual void VectorProduct(const Vector &y); 53 virtual void ProjectOntoPlane(const Vector &y); 54 virtual void ProjectIt(const Vector &y); 55 virtual Vector Projection(const Vector &y) const; 57 56 virtual void Zero(); 58 57 virtual void One(const double one); 59 58 virtual void Init(const double x1, const double x2, const double x3); 60 59 virtual void Normalize(); 61 virtual void Translate(const Vector * constx);62 virtual void Mirror(const Vector * constx);60 virtual void Translate(const Vector &x); 61 virtual void Mirror(const Vector &x); 63 62 virtual void Scale(const double ** const factor); 64 63 virtual void Scale(const double * const factor); … … 67 66 virtual bool InverseMatrixMultiplication(const double * const M); 68 67 virtual void KeepPeriodic(const double * const matrix); 69 virtual void LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors); 70 virtual double CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const; 71 virtual bool GetOneNormalVector(const Vector * const x1); 68 virtual void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors); 69 virtual bool GetOneNormalVector(const Vector &x1); 72 70 virtual bool MakeNormalTo(const Vector &y1); 73 71 //bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c); -
src/vector_ops.cpp
r72e7fa r273382 121 121 // normalise this vector with respect to axis 122 122 a.CopyVector(vec); 123 a.ProjectOntoPlane( &axis);123 a.ProjectOntoPlane(axis); 124 124 // construct normal vector 125 125 try { … … 135 135 y.Scale(sin(alpha)); 136 136 a.Scale(cos(alpha)); 137 res = vec.Projection( &axis);137 res = vec.Projection(axis); 138 138 // add scaled normal vector onto this vector 139 res .AddVector(&y);139 res += y; 140 140 // add part in axis direction 141 res .AddVector(&a);141 res += a; 142 142 return res; 143 143 }; … … 197 197 Vector parallel; 198 198 double factor = 0.; 199 if (fabs(a.ScalarProduct( &b)*a.ScalarProduct(&b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {199 if (fabs(a.ScalarProduct(b)*a.ScalarProduct(b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) { 200 200 parallel = Line1a - Line2a; 201 factor = parallel.ScalarProduct( &a)/a.Norm();201 factor = parallel.ScalarProduct(a)/a.Norm(); 202 202 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 203 203 res = Line2a; … … 206 206 } else { 207 207 parallel = Line1a - Line2b; 208 factor = parallel.ScalarProduct( &a)/a.Norm();208 factor = parallel.ScalarProduct(a)/a.Norm(); 209 209 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 210 210 res = Line2b; … … 221 221 double s; 222 222 Vector temp1, temp2; 223 temp1 .CopyVector(&c);224 temp1.VectorProduct( &b);225 temp2 .CopyVector(&a);226 temp2.VectorProduct( &b);223 temp1 = c; 224 temp1.VectorProduct(b); 225 temp2 = a; 226 temp2.VectorProduct(b); 227 227 Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl; 228 228 if (fabs(temp2.NormSquared()) > MYEPSILON) 229 s = temp1.ScalarProduct( &temp2)/temp2.NormSquared();229 s = temp1.ScalarProduct(temp2)/temp2.NormSquared(); 230 230 else 231 231 s = 0.; 232 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct( &temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;232 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl; 233 233 234 234 // construct intersection
Note:
See TracChangeset
for help on using the changeset viewer.
