Changeset a92c27


Ignore:
Timestamp:
May 25, 2016, 7:13:59 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Children:
46e561
Parents:
4492f1
git-author:
Frederik Heber <heber@…> (07/12/14 16:19:46)
git-committer:
Frederik Heber <heber@…> (05/25/16 07:13:59)
Message:

Removed all IsZero() checking and special cases for the triangle idea.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/SphericalPointDistribution.cpp

    r4492f1 ra92c27  
    697697      _referencepositions, _currentpositions);
    698698
    699   if ((!oldCenter.IsZero()) && (!newCenter.IsZero())) {
    700     LOG(4, "DEBUG: oldCenter is " << oldCenter << ", newCenter is " << newCenter);
    701     oldCenter.Normalize();
    702     newCenter.Normalize();
    703     if (!oldCenter.IsEqualTo(newCenter)) {
    704       // calculate rotation axis and angle
    705       Rotation.first = oldCenter;
    706       Rotation.first.VectorProduct(newCenter);
    707       Rotation.second = oldCenter.Angle(newCenter); // /(M_PI/2.);
    708     } else {
    709       // no rotation required anymore
    710     }
     699  ASSERT( !oldCenter.IsZero() && !newCenter.IsZero(),
     700      "findPlaneAligningRotation() - either old "+toString(oldCenter)
     701      +" or new center "+toString(newCenter)+" are zero.");
     702  LOG(4, "DEBUG: oldCenter is " << oldCenter << ", newCenter is " << newCenter);
     703  if (!oldCenter.IsEqualTo(newCenter)) {
     704    // calculate rotation axis and angle
     705    Rotation.first = oldCenter;
     706    Rotation.first.VectorProduct(newCenter);
     707    Rotation.first.Normalize();
     708    // construct reference vector to determine direction of rotation
     709    const double sign = determineSignOfRotation(newCenter, oldCenter, Rotation.first);
     710    Rotation.second = sign * oldCenter.Angle(newCenter);
    711711  } else {
    712     LOG(4, "DEBUG: oldCenter is " << oldCenter << ", newCenter is " << newCenter);
    713     if ((oldCenter.IsZero()) && (newCenter.IsZero())) {
    714       // either oldCenter or newCenter (or both) is directly at origin
    715       if (_currentpositions.indices.size() == 2) {
    716         // line case
    717         Vector oldPosition = _currentpositions.polygon[*_currentpositions.indices.begin()];
    718         Vector newPosition = _referencepositions.polygon[0];
    719         // check whether we need to rotate at all
    720         if (!oldPosition.IsEqualTo(newPosition)) {
    721           Rotation.first = oldPosition;
    722           Rotation.first.VectorProduct(newPosition);
    723           // orientation will fix the sign here eventually
    724           Rotation.second = oldPosition.Angle(newPosition);
    725         } else {
    726           // no rotation required anymore
    727         }
    728       } else {
    729         // triangle case
    730         // both triangles/planes have same center, hence get axis by
    731         // VectorProduct of Normals
    732         Plane newplane(_referencepositions.polygon[0], _referencepositions.polygon[1], _referencepositions.polygon[2]);
    733         VectorArray_t vectors;
    734         for (IndexList_t::const_iterator iter = _currentpositions.indices.begin();
    735             iter != _currentpositions.indices.end(); ++iter)
    736           vectors.push_back(_currentpositions.polygon[*iter]);
    737         Plane oldplane(vectors[0], vectors[1], vectors[2]);
    738         Vector oldPosition = oldplane.getNormal();
    739         Vector newPosition = newplane.getNormal();
    740         // check whether we need to rotate at all
    741         if (!oldPosition.IsEqualTo(newPosition)) {
    742           Rotation.first = oldPosition;
    743           Rotation.first.VectorProduct(newPosition);
    744           Rotation.first.Normalize();
    745 
    746           // construct reference vector to determine direction of rotation
    747           const double sign = determineSignOfRotation(oldPosition, newPosition, Rotation.first);
    748           Rotation.second = sign * oldPosition.Angle(newPosition);
    749           LOG(5, "DEBUG: Rotating plane normals by " << Rotation.second
    750               << " around axis " << Rotation.first);
    751         } else {
    752           // else do nothing
    753         }
    754       }
    755     } else {
    756       // TODO: we can't do anything here, but this case needs to be dealt with when
    757       // we have no ideal geometries anymore
    758       if ((oldCenter-newCenter).Norm() > warn_amplitude)
    759         ELOG(2, "oldCenter is " << oldCenter << ", yet newCenter is " << newCenter);
    760       // else they are considered close enough
    761       dontcheck = true;
    762     }
     712    // no rotation required anymore
    763713  }
    764714
     
    801751      << oldPosition.Norm() << ") and newPosition is " << newPosition << " length(: "
    802752      << newPosition.Norm() << ")");
     753
    803754  if (!oldPosition.IsEqualTo(newPosition)) {
    804     if ((!oldCenter.IsZero()) && (!newCenter.IsZero())) {
    805       // we rotate at oldCenter and around the radial direction, which is again given
    806       // by oldCenter.
    807       Rotation.first = oldCenter;
    808       Rotation.first.Normalize();  // note weighted sum of normalized weight is not normalized
    809       LOG(6, "DEBUG: Using oldCenter " << oldCenter << " as rotation center and "
    810           << Rotation.first << " as axis.");
    811       oldPosition -= oldCenter;
    812       newPosition -= oldCenter;
    813       oldPosition = (oldPosition - oldPosition.Projection(Rotation.first));
    814       newPosition = (newPosition - newPosition.Projection(Rotation.first));
    815       LOG(6, "DEBUG: Positions after projection are " << oldPosition << " and " << newPosition);
    816     } else {
    817       if (remainingnew.indices.size() == 2) {
    818         // line situation
    819         try {
    820           Plane oldplane(oldPosition, oldCenter, newPosition);
    821           Rotation.first = oldplane.getNormal();
    822           LOG(6, "DEBUG: Plane is " << oldplane << " and normal is " << Rotation.first);
    823         } catch (LinearDependenceException &e) {
    824           LOG(6, "DEBUG: Vectors defining plane are linearly dependent.");
    825           // oldPosition and newPosition are on a line, just flip when not equal
    826           if (!oldPosition.IsEqualTo(newPosition)) {
    827             Rotation.first.Zero();
    828             Rotation.first.GetOneNormalVector(oldPosition);
    829             LOG(6, "DEBUG: For flipping we use Rotation.first " << Rotation.first);
    830             assert( Rotation.first.ScalarProduct(oldPosition) < std::numeric_limits<double>::epsilon()*1e4);
    831   //              Rotation.second = M_PI;
    832           } else {
    833             LOG(6, "DEBUG: oldPosition and newPosition are equivalent.");
    834           }
    835         }
    836       } else {
    837         // triangle situation
    838         Plane oldplane(remainingold.polygon[0], remainingold.polygon[1], remainingold.polygon[2]);
    839         Rotation.first = oldplane.getNormal();
    840         LOG(6, "DEBUG: oldPlane is " << oldplane << " and normal is " << Rotation.first);
    841         oldPosition.ProjectOntoPlane(Rotation.first);
    842         LOG(6, "DEBUG: Positions after projection are " << oldPosition << " and " << newPosition);
    843       }
    844     }
     755    // we rotate at oldCenter and around the radial direction, which is again given
     756    // by oldCenter.
     757    Rotation.first = oldCenter;
     758    Rotation.first.Normalize();  // note weighted sum of normalized weight is not normalized
     759    LOG(6, "DEBUG: Using oldCenter " << oldCenter << " as rotation center and "
     760        << Rotation.first << " as axis.");
     761    oldPosition -= oldCenter;
     762    newPosition -= oldCenter;
     763    oldPosition = (oldPosition - oldPosition.Projection(Rotation.first));
     764    newPosition = (newPosition - newPosition.Projection(Rotation.first));
     765    LOG(6, "DEBUG: Positions after projection are " << oldPosition << " and " << newPosition);
     766
    845767    // construct reference vector to determine direction of rotation
    846768    const double sign = determineSignOfRotation(oldPosition, newPosition, Rotation.first);
     
    915837#ifndef NDEBUG
    916838      // check: rotated "newCenter" should now equal oldCenter
    917       {
     839      // we don't check in case of two points as these lie on a great circle
     840      // and the center cannot stably be recalculated. We may reactivate this
     841      // when we calculate centers only once
     842      if (oldSet.indices.size() > 2) {
    918843        Vector oldCenter;
    919844        Vector rotatednewCenter;
Note: See TracChangeset for help on using the changeset viewer.