Ignore:
Timestamp:
Mar 28, 2012, 1:23:11 PM (13 years ago)
Author:
Frederik Heber <heber@…>
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:
03a713
Parents:
368207
git-author:
Frederik Heber <heber@…> (03/14/12 20:22:42)
git-committer:
Frederik Heber <heber@…> (03/28/12 13:23:11)
Message:

Added BoundaryTriangleSet::IsInsideTriangle().

  • this is preparatory for finding a bug in GetClosestPointInsideTriangle().
  • refactored in-test triangle creation into distinct function.
  • added extensive unit test on this function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tesselation/BoundaryTriangleSet.cpp

    r368207 r471dec  
    371371;
    372372
     373/** Checks whether a given point is inside the plane of the triangle and inside the
     374 * bounds defined by its BoundaryLineSet's.
     375 *
     376 * @param point point to check
     377 * @return true - point is inside place and inside all BoundaryLine's
     378 */
     379bool BoundaryTriangleSet::IsInsideTriangle(const Vector &point) const
     380{
     381  Info FunctionInfo(__func__);
     382
     383  // check if it's inside the plane
     384  try {
     385    Plane trianglePlane(
     386        endpoints[0]->node->getPosition(),
     387        endpoints[1]->node->getPosition(),
     388        endpoints[2]->node->getPosition());
     389    if (!trianglePlane.isContained(point)) {
     390      LOG(1, "INFO: Point " << point << " is not inside plane " << trianglePlane << " by "
     391          << trianglePlane.distance(point) << ".");
     392      return false;
     393    }
     394  } catch(LinearDependenceException) {
     395    // triangle is degenerated, it's just a line (i.e. one endpoint is right in between two others
     396    for (size_t i = 0; i < NDIM; ++i) {
     397      try {
     398        Line l = makeLineThrough(
     399            lines[i]->endpoints[0]->node->getPosition(),
     400            lines[i]->endpoints[1]->node->getPosition());
     401        if (l.isContained(GetThirdEndpoint(lines[i])->node->getPosition())) {
     402          // we have the largest of the three lines
     403          LOG(1, "INFO: Linear-dependent case where point " << point << " is on line " << l << ".");
     404          return (l.isContained(point));
     405        }
     406      } catch(ZeroVectorException) {
     407        // two points actually coincide
     408        try {
     409          Line l = makeLineThrough(
     410              lines[i]->endpoints[0]->node->getPosition(),
     411              GetThirdEndpoint(lines[i])->node->getPosition());
     412          LOG(1, "INFO: Degenerated case where point " << point << " is on line " << l << ".");
     413          return (l.isContained(point));
     414        } catch(ZeroVectorException) {
     415          // all three points coincide
     416          if (point.DistanceSquared(lines[i]->endpoints[0]->node->getPosition()) < MYEPSILON) {
     417            LOG(1, "INFO: Full-Degenerated case where point " << point << " is on three endpoints "
     418                << lines[i]->endpoints[0]->node->getPosition() << ".");
     419            return true;
     420          }
     421          else return false;
     422        }
     423      }
     424    }
     425  }
     426
     427  // check whether it lies on the correct side as given by third endpoint for
     428  // each BoundaryLine.
     429  // NOTE: we assume here that endpoints are linear independent, as the case
     430  // has been caught before already extensively
     431  for (size_t i = 0; i < NDIM; ++i) {
     432    Line l = makeLineThrough(
     433        lines[i]->endpoints[0]->node->getPosition(),
     434        lines[i]->endpoints[1]->node->getPosition());
     435    Vector onLine( l.getClosestPoint(point) );
     436    LOG(1, "INFO: Closest point on boundary line is " << onLine << ".");
     437    Vector inTriangleDirection( GetThirdEndpoint(lines[i])->node->getPosition() - onLine );
     438    Vector inPointDirection(point - onLine);
     439    if ((inTriangleDirection.NormSquared() > MYEPSILON) && (inPointDirection.NormSquared() > MYEPSILON))
     440      if (inTriangleDirection.ScalarProduct(inPointDirection) < -MYEPSILON)
     441        return false;
     442  }
     443
     444  return true;
     445}
     446
     447
    373448/** Returns the endpoint which is not contained in the given \a *line.
    374449 * \param *line baseline defining two endpoints
Note: See TracChangeset for help on using the changeset viewer.