Ignore:
Timestamp:
Aug 3, 2009, 8:10:09 AM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
0e2190, 834ff3
Parents:
3dc682
Message:

We are one step further in fixing the convex hull: There are two functions of Saskia Metzler missing, but then we may proceed with testing whether the simple correction scheme of the convex envelope works, but one thing: Right now we cannot associate a Tesselation to its molecule as the snake bites it's one tail. Hence, the next commit will consist of fixing this bad-OOP issue.

  • Makefile.am: Just some alphabetical resorting.
  • atom::atom() new copy constructor
  • builder.cpp: some output for cluster volume, molecule::AddCopyAtom() uses new copy constructor
  • FillBoxWithMolecule() - new function to fill the remainder of the simulation box with some given filler molecules. Makes explicit use of the tesselated surfaces
  • find_convex_border() - InsertStraddlingPoints() and CorrectConcaveBaselines() is called to correct for atoms outside the envelope and caused-by concave points
  • Tesselation::InsertStraddlingPoints() enlarges the envelope for all atoms found outside, Tesselation::CorrectConcaveBaselines() corrects all found baselines if the adjacent triangles are concave by flipping.
  • boundary.cpp: Lots of helper routines for stuff further below:
  • The following routines are needed to check whether point is in- or outside:
  • FIX: Tesselation::AddPoint() - newly created BoundaryPoint is removed if already present.

Problem: We want to associate a Tesselation class with each molecule class. However, so far we have to know about atoms and bond and molecules inside the Tesselation. We have to remove this dependency and create some intermediate class which enables/encapsulates the access to Vectors, e.g. hidden inside the atom class. This is also good OOP! The Tesselation also only needs a set of Vectors, not more!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/vector.cpp

    r3dc682 r4e4940  
    196196};
    197197
     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 */
     214bool 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 */
     247bool 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
    198285/** Calculates the projection of a vector onto another \a *y.
    199286 * \param *y array to second vector
     
    453540};
    454541
    455 /** Do a matrix multiplication with \a *matrix' inverse.
     542/** Do a matrix multiplication with the \a *A' inverse.
    456543 * \param *matrix NDIM_NDIM array
    457544 */
Note: See TracChangeset for help on using the changeset viewer.