source: src/Shapes/BaseShapes.cpp@ d76a7c

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
Last change on this file since d76a7c was d76a7c, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added simpler method to create cuboids with arbitrary corners

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 * BaseShapes_impl.cpp
3 *
4 * Created on: Jun 18, 2010
5 * Author: crueger
6 */
7
8#include "Shapes/BaseShapes.hpp"
9#include "Shapes/BaseShapes_impl.hpp"
10#include "Shapes/ShapeOps.hpp"
11
12#include "vector.hpp"
13#include "Helpers/Assert.hpp"
14
15#include <cmath>
16#include <algorithm>
17
18bool Sphere_impl::isInside(const Vector &point){
19 return point.NormSquared()<=1;
20}
21
22bool Sphere_impl::isOnSurface(const Vector &point){
23 return fabs(point.NormSquared()-1)<MYEPSILON;
24}
25
26Vector Sphere_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
27 if(!isOnSurface(point)){
28 throw NotOnSurfaceException(__FILE__,__LINE__);
29 }
30 return point;
31}
32
33string Sphere_impl::toString(){
34 return "Sphere()";
35}
36
37Shape Sphere(){
38 Shape::impl_ptr impl = Shape::impl_ptr(new Sphere_impl());
39 return Shape(impl);
40}
41
42Shape Sphere(const Vector &center,double radius){
43 return translate(resize(Sphere(),radius),center);
44}
45
46Shape Ellipsoid(const Vector &center, const Vector &radius){
47 return translate(stretch(Sphere(),radius),center);
48}
49
50bool Cuboid_impl::isInside(const Vector &point){
51 return fabs(point[0])<=1 && fabs(point[1])<=1 && fabs(point[2])<=1;
52}
53
54bool Cuboid_impl::isOnSurface(const Vector &point){
55 bool retVal = isInside(point);
56 // test all borders of the cuboid
57 // double fabs
58 retVal = retVal &&
59 ((fabs(fabs(point[0])-1) < MYEPSILON) ||
60 (fabs(fabs(point[1])-1) < MYEPSILON) ||
61 (fabs(fabs(point[2])-1) < MYEPSILON));
62 return retVal;
63}
64
65Vector Cuboid_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
66 if(!isOnSurface(point)){
67 throw NotOnSurfaceException(__FILE__,__LINE__);
68 }
69 Vector res;
70 // figure out on which sides the Vector lies (maximum 3, when it is in a corner)
71 for(int i=NDIM;i--;){
72 if(fabs(fabs(point[i])-1)<MYEPSILON){
73 // add the scaled (-1/+1) Vector to the set of surface vectors
74 res[i] = point[i];
75 }
76 }
77 ASSERT(res.NormSquared()>=1 && res.NormSquared()<=3,"To many or to few sides found for this Vector");
78
79 res.Normalize();
80 return res;
81}
82
83string Cuboid_impl::toString(){
84 return "Cuboid()";
85}
86
87Shape Cuboid(){
88 Shape::impl_ptr impl = Shape::impl_ptr(new Cuboid_impl());
89 return Shape(impl);
90}
91
92Shape Cuboid(const Vector &corner1, const Vector &corner2){
93 // make sure the two edges are upper left front and lower right back
94 Vector sortedC1;
95 Vector sortedC2;
96 for(int i=NDIM;i--;){
97 sortedC1[i] = min(corner1[i],corner2[i]);
98 sortedC2[i] = max(corner1[i],corner2[i]);
99 ASSERT(corner1[i]!=corner2[i],"Given points for cuboid edges did not define a valid space");
100 }
101 // get the middle point
102 Vector middle = (1./2.)*(sortedC1+sortedC2);
103 Vector factors = sortedC2-middle;
104 return translate(stretch(Cuboid(),factors),middle);
105}
Note: See TracBrowser for help on using the repository browser.