Changeset 76c0d6 for src/vector_ops.cpp
- Timestamp:
- Jun 4, 2010, 9:28:46 AM (15 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, 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:
- 2c8934
- Parents:
- e05826 (diff), 27ac00 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/vector_ops.cpp ¶
re05826 r76c0d6 15 15 #include "Helpers/fast_functions.hpp" 16 16 #include "Exceptions/LinearDependenceException.hpp" 17 #include "Exceptions/SkewException.hpp" 17 18 18 19 #include <gsl/gsl_linalg.h> … … 110 111 return true; 111 112 }; 112 113 /** Rotates the vector relative to the origin around the axis given by \a *axis by an angle of \a alpha.114 * \param *axis rotation axis115 * \param alpha rotation angle in radian116 */117 Vector RotateVector(const Vector &vec,const Vector &axis, const double alpha)118 {119 Vector a,y;120 Vector res;121 // normalise this vector with respect to axis122 a = vec;123 a.ProjectOntoPlane(axis);124 // construct normal vector125 try {126 y = Plane(axis,a,0).getNormal();127 }128 catch (MathException &excp) {129 // The normal vector cannot be created if there is linar dependency.130 // Then the vector to rotate is on the axis and any rotation leads to the vector itself.131 return vec;132 }133 y.Scale(vec.Norm());134 // scale normal vector by sine and this vector by cosine135 y.Scale(sin(alpha));136 a.Scale(cos(alpha));137 res = vec.Projection(axis);138 // add scaled normal vector onto this vector139 res += y;140 // add part in axis direction141 res += a;142 return res;143 };144 145 /** Calculates the intersection of the two lines that are both on the same plane.146 * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html147 * \param *out output stream for debugging148 * \param *Line1a first vector of first line149 * \param *Line1b second vector of first line150 * \param *Line2a first vector of second line151 * \param *Line2b second vector of second line152 * \return true - \a this will contain the intersection on return, false - lines are parallel153 */154 Vector GetIntersectionOfTwoLinesOnPlane(const Vector &Line1a, const Vector &Line1b, const Vector &Line2a, const Vector &Line2b)155 {156 Info FunctionInfo(__func__);157 158 Vector res;159 160 auto_ptr<GSLMatrix> M = auto_ptr<GSLMatrix>(new GSLMatrix(4,4));161 162 M->SetAll(1.);163 for (int i=0;i<3;i++) {164 M->Set(0, i, Line1a[i]);165 M->Set(1, i, Line1b[i]);166 M->Set(2, i, Line2a[i]);167 M->Set(3, i, Line2b[i]);168 }169 170 //Log() << Verbose(1) << "Coefficent matrix is:" << endl;171 //for (int i=0;i<4;i++) {172 // for (int j=0;j<4;j++)173 // cout << "\t" << M->Get(i,j);174 // cout << endl;175 //}176 if (fabs(M->Determinant()) > MYEPSILON) {177 Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl;178 throw LinearDependenceException(__FILE__,__LINE__);179 }180 181 Log() << Verbose(1) << "INFO: Line1a = " << Line1a << ", Line1b = " << Line1b << ", Line2a = " << Line2a << ", Line2b = " << Line2b << "." << endl;182 183 184 // constuct a,b,c185 Vector a = Line1b - Line1a;186 Vector b = Line2b - Line2a;187 Vector c = Line2a - Line1a;188 Vector d = Line2b - Line1b;189 Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl;190 if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {191 res.Zero();192 Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl;193 throw LinearDependenceException(__FILE__,__LINE__);194 }195 196 // check for parallelity197 Vector parallel;198 double factor = 0.;199 if (fabs(a.ScalarProduct(b)*a.ScalarProduct(b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {200 parallel = Line1a - Line2a;201 factor = parallel.ScalarProduct(a)/a.Norm();202 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {203 res = Line2a;204 Log() << Verbose(1) << "Lines conincide." << endl;205 return res;206 } else {207 parallel = Line1a - Line2b;208 factor = parallel.ScalarProduct(a)/a.Norm();209 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {210 res = Line2b;211 Log() << Verbose(1) << "Lines conincide." << endl;212 return res;213 }214 }215 Log() << Verbose(1) << "Lines are parallel." << endl;216 res.Zero();217 throw LinearDependenceException(__FILE__,__LINE__);218 }219 220 // obtain s221 double s;222 Vector temp1, temp2;223 temp1 = c;224 temp1.VectorProduct(b);225 temp2 = a;226 temp2.VectorProduct(b);227 Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl;228 if (fabs(temp2.NormSquared()) > MYEPSILON)229 s = temp1.ScalarProduct(temp2)/temp2.NormSquared();230 else231 s = 0.;232 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;233 234 // construct intersection235 res = a;236 res.Scale(s);237 res += Line1a;238 Log() << Verbose(1) << "Intersection is at " << res << "." << endl;239 240 return res;241 };
Note:
See TracChangeset
for help on using the changeset viewer.