Changeset 46670d
- Timestamp:
- Aug 8, 2009, 7:19:23 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:
- 8bb475f
- Parents:
- 055861
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/vector.cpp
r055861 r46670d 213 213 * \return true - \a this contains intersection point on return, false - line is parallel to plane 214 214 */ 215 bool Vector::GetIntersectionWithPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset, Vector * LineVector, Vector *LineVector2)215 bool Vector::GetIntersectionWithPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset, Vector *Origin, Vector *LineVector) 216 216 { 217 217 double factor; 218 Vector Direction ;218 Vector Direction, helper; 219 219 220 220 // find intersection of a line defined by Offset and Direction with a plane defined by triangle 221 Direction.CopyVector(LineVector2); 222 Direction.SubtractVector(LineVector); 223 if (Direction.ScalarProduct(PlaneNormal) < MYEPSILON) 221 Direction.CopyVector(LineVector); 222 Direction.SubtractVector(Origin); 223 factor = Direction.ScalarProduct(PlaneNormal); 224 if (factor < MYEPSILON) { // Uniqueness: line parallel to plane? 225 *out << Verbose(2) << "WARNING: Line is parallel to plane, no intersection." << endl; 224 226 return false; 225 factor = LineVector->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 227 } 228 helper.CopyVector(PlaneOffset); 229 helper.SubtractVector(LineVector); 230 factor = helper.ScalarProduct(PlaneNormal)/factor; 231 //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 226 232 Direction.Scale(factor); 227 233 CopyVector(LineVector); 228 SubtractVector(&Direction);234 AddVector(&Direction); 229 235 230 236 // test whether resulting vector really is on plane 231 Direction.CopyVector(this); 232 Direction.SubtractVector(PlaneOffset); 233 if (Direction.ScalarProduct(PlaneNormal) > MYEPSILON) 237 helper.CopyVector(this); 238 helper.SubtractVector(PlaneOffset); 239 if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) { 240 *out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl; 234 241 return true; 235 else 242 } else { 243 *out << Verbose(2) << "WARNING: Intersection point " << *this << " is not on plane." << endl; 236 244 return false; 245 } 237 246 }; 238 247 … … 244 253 * \param *Line2a first vector of second line 245 254 * \param *Line2b second vector of second line 255 * \param *PlaneNormal normal of plane, is supplemental/arbitrary 246 256 * \return true - \a this will contain the intersection on return, false - lines are parallel 247 257 */ 248 bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b) 249 { 250 double k1,a1,h1,b1,k2,a2,h2,b2; 251 // equation for line 1 252 if (fabs(Line1a->x[0] - Line2a->x[0]) < MYEPSILON) { 253 k1 = 0; 254 h1 = 0; 255 } else { 256 k1 = (Line1a->x[1] - Line2a->x[1])/(Line1a->x[0] - Line2a->x[0]); 257 h1 = (Line1a->x[2] - Line2a->x[2])/(Line1a->x[0] - Line2a->x[0]); 258 } 259 a1 = 0.5*((Line1a->x[1] + Line2a->x[1]) - k1*(Line1a->x[0] + Line2a->x[0])); 260 b1 = 0.5*((Line1a->x[2] + Line2a->x[2]) - h1*(Line1a->x[0] + Line2a->x[0])); 261 262 // equation for line 2 263 if (fabs(Line2a->x[0] - Line2a->x[0]) < MYEPSILON) { 264 k1 = 0; 265 h1 = 0; 266 } else { 267 k1 = (Line2a->x[1] - Line2a->x[1])/(Line2a->x[0] - Line2a->x[0]); 268 h1 = (Line2a->x[2] - Line2a->x[2])/(Line2a->x[0] - Line2a->x[0]); 269 } 270 a1 = 0.5*((Line2a->x[1] + Line2a->x[1]) - k1*(Line2a->x[0] + Line2a->x[0])); 271 b1 = 0.5*((Line2a->x[2] + Line2a->x[2]) - h1*(Line2a->x[0] + Line2a->x[0])); 272 273 // calculate cross point 274 if (fabs((a1-a2)*(h1-h2) - (b1-b2)*(k1-k2)) < MYEPSILON) { 275 x[0] = (a2-a1)/(k1-k2); 276 x[1] = (k1*a2-k2*a1)/(k1-k2); 277 x[2] = (h1*b2-h2*b1)/(h1-h2); 278 *out << Verbose(4) << "Lines do intersect at " << this << "." << endl; 279 return true; 280 } else { 281 *out << Verbose(4) << "Lines do not intersect." << endl; 282 return false; 283 } 258 bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *PlaneNormal) 259 { 260 double factor1, factor2; 261 Vector helper, Line, LineNormal, *OtherNormal = NULL; 262 const Vector *Normal; 263 bool result = false; 264 265 // create Plane normal vector 266 if (PlaneNormal == NULL) { 267 OtherNormal = new Vector(0.,0.,0.); 268 if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2a)) 269 if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2b)) { 270 *out << Verbose(1) << "ERROR: GetIntersectionOfTwoLinesOnPlane() cannot create a normal of the plane, everything is linear dependent." << endl; 271 return false; 272 } 273 Normal = OtherNormal; 274 } else 275 Normal = PlaneNormal; 276 *out << Verbose(3) << "INFO: Normal of plane is " << *Normal << "." << endl; 277 278 // create normal vector to one line 279 Line.CopyVector(Line1b); 280 Line.SubtractVector(Line1a); 281 LineNormal.MakeNormalVector(&Line, Normal); 282 *out << Verbose(3) << "INFO: Normal of first line is " << LineNormal << "." << endl; 283 284 // check if lines are parallel 285 helper.CopyVector(Line2b); 286 helper.SubtractVector(Line2a); 287 if (fabs(helper.ScalarProduct(&LineNormal)) < MYEPSILON) { 288 *out << Verbose(1) << "Lines " << helper << " and " << Line << " are parallel, no cross point!" << endl; 289 result = false; 290 } else { 291 helper.CopyVector(Line2a); 292 helper.SubtractVector(Line1a); 293 factor1 = helper.ScalarProduct(&LineNormal); 294 helper.CopyVector(Line2b); 295 helper.SubtractVector(Line1a); 296 factor2 = helper.ScalarProduct(&LineNormal); 297 if (fabs(factor2) > MYEPSILON) { 298 CopyVector(Line2a); 299 helper.Scale(factor1/factor2); 300 AddVector(&helper); 301 result = true; 302 } else { 303 Zero(); 304 result = false; 305 } 306 } 307 308 if (OtherNormal != NULL) 309 delete(OtherNormal); 310 311 return result; 284 312 }; 285 313 … … 352 380 * @return true - vector is zero, false - vector is not 353 381 */ 354 bool Vector::IsNull() 382 bool Vector::IsNull() const 355 383 { 356 384 return (fabs(x[0]+x[1]+x[2]) < MYEPSILON); … … 692 720 { 693 721 bool result = false; 722 double factor = y1->Projection(this)/y1->Norm()/y1->Norm(); 694 723 Vector x1; 695 724 x1.CopyVector(y1); 696 x1.Scale( x1.Projection(this));725 x1.Scale(factor); 697 726 SubtractVector(&x1); 698 727 for (int i=NDIM;i--;) -
src/vector.hpp
r055861 r46670d 28 28 double NormSquared() const; 29 29 double Angle(const Vector *y) const; 30 bool IsNull() ;30 bool IsNull() const; 31 31 32 32 void AddVector(const Vector *y); … … 51 51 void LinearCombinationOfVectors(const Vector *x1, const Vector *x2, const Vector *x3, double *factors); 52 52 double CutsPlaneAt(Vector *A, Vector *B, Vector *C); 53 bool GetIntersectionWithPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset, Vector * LineVector, Vector *LineVector2);54 bool GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b );53 bool GetIntersectionWithPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset, Vector *Origin, Vector *LineVector); 54 bool GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *Normal = NULL); 55 55 bool GetOneNormalVector(const Vector *x1); 56 56 bool MakeNormalVector(const Vector *y1);
Note:
See TracChangeset
for help on using the changeset viewer.