- Timestamp:
- Jan 10, 2010, 7:24:02 PM (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:
- 2793ef
- Parents:
- 31a6af
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/vector.cpp
r31a6af r9d6308 9 9 #include "helpers.hpp" 10 10 #include "info.hpp" 11 #include "gslmatrix.hpp" 11 12 #include "leastsquaremin.hpp" 12 13 #include "log.hpp" … … 293 294 294 295 /** Calculates the intersection of the two lines that are both on the same plane. 295 * We construct auxiliary plane with its vector normal to one line direction and the PlaneNormal, then a vector 296 * from the first line's offset onto the plane. Finally, scale by factor is 1/cos(angle(line1,line2..)) = 1/SP(...), and 297 * project onto the first line's direction and add its offset. 296 * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html 298 297 * \param *out output stream for debugging 299 298 * \param *Line1a first vector of first line … … 307 306 { 308 307 Info FunctionInfo(__func__); 309 Vector Direction, OtherDirection; 310 gsl_matrix *A = gsl_matrix_alloc(NDIM,NDIM); 311 gsl_vector *b = gsl_vector_alloc(NDIM); 312 gsl_vector *x = gsl_vector_alloc(NDIM); 313 gsl_permutation *perm = NULL; 314 int signum; 315 316 // construct both direction vectors 317 Direction.CopyVector(Line1b); 318 Direction.SubtractVector(Line1a); 319 if (Direction.IsZero()) 308 Vector a; 309 Vector b; 310 Vector c; 311 312 GSLMatrix *M = new GSLMatrix(4,4); 313 314 M->SetAll(1.); 315 for (int i=0;i<3;i++) { 316 M->Set(0, i, Line1a->x[i]); 317 M->Set(1, i, Line1b->x[i]); 318 M->Set(2, i, Line2a->x[i]); 319 M->Set(3, i, Line2b->x[i]); 320 } 321 if (fabs(M->Determinant()) < MYEPSILON) 320 322 return false; 321 OtherDirection.CopyVector(Line2b); 322 OtherDirection.SubtractVector(Line2a); 323 if (OtherDirection.IsZero()) 324 return false; 325 326 // set vector 327 for (int i=0;i<NDIM;i++) 328 gsl_vector_set(b, i, Line1a->x[i]-Line2a->x[i]); 329 Log() << Verbose(1) << "b = " << endl; 330 gsl_vector_fprintf(stdout, b, "%g"); 331 332 // set matrix 333 for (int i=0;i<NDIM;i++) 334 gsl_matrix_set(A, 0, i, -Direction.x[i]); 335 for (int i=0;i<NDIM;i++) 336 gsl_matrix_set(A, 1, i, OtherDirection.x[i]); 337 for (int i=0;i<NDIM;i++) 338 gsl_matrix_set(A, 2, i, 1.); 339 Log() << Verbose(1) << "A = " << endl; 340 gsl_matrix_fprintf(stdout, A, "%g"); 341 342 // Solve A x=b for x 343 perm = gsl_permutation_alloc(NDIM); 344 gsl_linalg_LU_decomp(A, perm, &signum); 345 gsl_linalg_LU_solve(A, perm, b, x); 346 gsl_permutation_free(perm); 347 gsl_vector_free(b); 348 gsl_matrix_free(A); 349 350 Log() << Verbose(1) << "Solution is " << gsl_vector_get(x,0) << ", " << gsl_vector_get(x,1) << "." << endl; 351 352 CopyVector(&Direction); 353 Scale(gsl_vector_get(x,0)); 323 324 // constuct a,b,c 325 a.CopyVector(Line1b); 326 a.SubtractVector(Line1a); 327 b.CopyVector(Line2b); 328 b.SubtractVector(Line2a); 329 c.CopyVector(Line2a); 330 c.SubtractVector(Line1a); 331 332 // obtain s 333 double s; 334 Vector temp1, temp2; 335 temp1.CopyVector(&c); 336 temp1.VectorProduct(&b); 337 temp2.CopyVector(&a); 338 temp2.VectorProduct(&b); 339 s = temp1.ScalarProduct(&temp2)/temp2.NormSquared(); 340 Log() << Verbose(1) << "Factor s is " << s << "." << endl; 341 342 // construct intersection 343 CopyVector(&a); 344 Scale(s); 354 345 AddVector(Line1a); 355 Log() << Verbose(1) << "INFO: First intersection is " << *this << "." << endl; 356 357 Vector test; 358 test.CopyVector(&OtherDirection); 359 test.Scale(gsl_vector_get(x,1)); 360 test.AddVector(Line2a); 361 Log() << Verbose(1) << "INFO: Second intersection is " << test << "." << endl; 362 test.SubtractVector(this); 363 364 gsl_vector_free(x); 365 366 if (test.IsZero()) 367 return true; 368 else 369 return false; 346 Log() << Verbose(1) << "Intersection is at " << *this << "." << endl; 347 348 return true; 370 349 }; 371 350
Note:
See TracChangeset
for help on using the changeset viewer.