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