Changeset 2319ed for src/vector.cpp
- Timestamp:
- Aug 3, 2009, 8:10:09 AM (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, 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:
- 0dbddc, 357fba
- Parents:
- e1589e
- File:
-
- 1 edited
-
src/vector.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/vector.cpp
re1589e r2319ed 196 196 }; 197 197 198 /** Calculates the intersection point between a line defined by \a *LineVector and \a *LineVector2 and a plane defined by \a *Normal and \a *PlaneOffset. 199 * According to [Bronstein] the vectorial plane equation is: 200 * -# \f$\stackrel{r}{\rightarrow} \cdot \stackrel{N}{\rightarrow} + D = 0\f$, 201 * where \f$\stackrel{r}{\rightarrow}\f$ is the vector to be testet, \f$\stackrel{N}{\rightarrow}\f$ is the plane's normal vector and 202 * \f$D = - \stackrel{a}{\rightarrow} \stackrel{N}{\rightarrow}\f$, the offset with respect to origin, if \f$\stackrel{a}{\rightarrow}\f$, 203 * is an offset vector onto the plane. The line is parametrized by \f$\stackrel{x}{\rightarrow} + k \stackrel{t}{\rightarrow}\f$, where 204 * \f$\stackrel{x}{\rightarrow}\f$ is the offset and \f$\stackrel{t}{\rightarrow}\f$ the directional vector (NOTE: No need to normalize 205 * the latter). Inserting the parametrized form into the plane equation and solving for \f$k\f$, which we insert then into the parametrization 206 * of the line yields the intersection point on the plane. 207 * \param *out output stream for debugging 208 * \param *PlaneNormal Plane's normal vector 209 * \param *PlaneOffset Plane's offset vector 210 * \param *LineVector first vector of line 211 * \param *LineVector2 second vector of line 212 * \return true - \a this contains intersection point on return, false - line is parallel to plane 213 */ 214 bool Vector::GetIntersectionWithPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset, Vector *LineVector, Vector *LineVector2) 215 { 216 double factor; 217 Vector Direction; 218 219 // find intersection of a line defined by Offset and Direction with a plane defined by triangle 220 Direction.CopyVector(LineVector2); 221 Direction.SubtractVector(LineVector); 222 if (Direction.ScalarProduct(PlaneNormal) < MYEPSILON) 223 return false; 224 factor = LineVector->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 225 Direction.Scale(factor); 226 CopyVector(LineVector); 227 SubtractVector(&Direction); 228 229 // test whether resulting vector really is on plane 230 Direction.CopyVector(this); 231 Direction.SubtractVector(PlaneOffset); 232 if (Direction.ScalarProduct(PlaneNormal) > MYEPSILON) 233 return true; 234 else 235 return false; 236 }; 237 238 /** Calculates the intersection of the two lines that are both on the same plane. 239 * Note that we do not check whether they are on the same plane. 240 * \param *out output stream for debugging 241 * \param *Line1a first vector of first line 242 * \param *Line1b second vector of first line 243 * \param *Line2a first vector of second line 244 * \param *Line2b second vector of second line 245 * \return true - \a this will contain the intersection on return, false - lines are parallel 246 */ 247 bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b) 248 { 249 double k1,a1,h1,b1,k2,a2,h2,b2; 250 // equation for line 1 251 if (fabs(Line1a->x[0] - Line2a->x[0]) < MYEPSILON) { 252 k1 = 0; 253 h1 = 0; 254 } else { 255 k1 = (Line1a->x[1] - Line2a->x[1])/(Line1a->x[0] - Line2a->x[0]); 256 h1 = (Line1a->x[2] - Line2a->x[2])/(Line1a->x[0] - Line2a->x[0]); 257 } 258 a1 = 0.5*((Line1a->x[1] + Line2a->x[1]) - k1*(Line1a->x[0] + Line2a->x[0])); 259 b1 = 0.5*((Line1a->x[2] + Line2a->x[2]) - h1*(Line1a->x[0] + Line2a->x[0])); 260 261 // equation for line 2 262 if (fabs(Line2a->x[0] - Line2a->x[0]) < MYEPSILON) { 263 k1 = 0; 264 h1 = 0; 265 } else { 266 k1 = (Line2a->x[1] - Line2a->x[1])/(Line2a->x[0] - Line2a->x[0]); 267 h1 = (Line2a->x[2] - Line2a->x[2])/(Line2a->x[0] - Line2a->x[0]); 268 } 269 a1 = 0.5*((Line2a->x[1] + Line2a->x[1]) - k1*(Line2a->x[0] + Line2a->x[0])); 270 b1 = 0.5*((Line2a->x[2] + Line2a->x[2]) - h1*(Line2a->x[0] + Line2a->x[0])); 271 272 // calculate cross point 273 if (fabs((a1-a2)*(h1-h2) - (b1-b2)*(k1-k2)) < MYEPSILON) { 274 x[0] = (a2-a1)/(k1-k2); 275 x[1] = (k1*a2-k2*a1)/(k1-k2); 276 x[2] = (h1*b2-h2*b1)/(h1-h2); 277 *out << Verbose(4) << "Lines do intersect at " << this << "." << endl; 278 return true; 279 } else { 280 *out << Verbose(4) << "Lines do not intersect." << endl; 281 return false; 282 } 283 }; 284 198 285 /** Calculates the projection of a vector onto another \a *y. 199 286 * \param *y array to second vector … … 453 540 }; 454 541 455 /** Do a matrix multiplication with \a *matrix' inverse.542 /** Do a matrix multiplication with the \a *A' inverse. 456 543 * \param *matrix NDIM_NDIM array 457 544 */
Note:
See TracChangeset
for help on using the changeset viewer.
