Permalink
Browse files

Remove rotation function from HyperEllipsoid/Rectangle

This functionality is replaced by using RealViews in GeomRegions.
  • Loading branch information...
awalter17 committed Nov 28, 2016
1 parent f8c9650 commit 37e5efb2254424a219864f860faefca314355ece
@@ -59,20 +59,13 @@
{
protected double[] semiAxisLengths;
protected double[][] rotationMatrix;
protected double[][] inverseRotationMatrix;
protected double[] position;
public AbstractGeometricShape( final int n )
{
super( n );
semiAxisLengths = new double[ n ];
initializeIdentityTransformationMatrix();
// //
position = new double[ n ];
}
@@ -93,7 +86,6 @@ public AbstractGeometricShape( final RealLocalizable center, final double[] semi
this.semiAxisLengths = new double[ semiAxisLengths.length ];
System.arraycopy( semiAxisLengths, 0, this.semiAxisLengths, 0, semiAxisLengths.length );
initializeIdentityTransformationMatrix();
// //
position = new double[ n ];
@@ -106,43 +98,6 @@ public AbstractGeometricShape( final RealLocalizable center, final double[] semi
}
}
/**
* Initialize the object with center, extension and rotation
*
* @param center
* position of the object's center in space.
* @param semiAxisLengths
* arrays with values of half of width/height/depth/...
* @param rotationMatrix
* rotation matrix with n times n entries.
*/
public AbstractGeometricShape( final RealLocalizable center, final double[] semiAxisLengths, final double[][] rotationMatrix )
{
super( center.numDimensions() );
assert ( n == semiAxisLengths.length );
assert ( n == rotationMatrix.length );
for ( int d = 0; d < n; d++ )
{
assert ( n == rotationMatrix[ d ].length );
}
this.semiAxisLengths = new double[ semiAxisLengths.length ];
System.arraycopy( semiAxisLengths, 0, this.semiAxisLengths, 0, semiAxisLengths.length );
this.rotationMatrix = new double[ n ][ n ];
copyMatrix( rotationMatrix, this.rotationMatrix );
this.inverseRotationMatrix = new double[ n ][ n ];
invertMatrix( this.rotationMatrix, this.inverseRotationMatrix );
// //
position = new double[ n ];
center.localize( position );
updateBoundingBox();
}
public double getSemiAxisLength( final int d )
{
return semiAxisLengths[ d ];
@@ -160,62 +115,6 @@ public void setSemiAxisLength( final double[] value )
updateBoundingBox();
}
public double[][] getRotationMatrix()
{
final double[][] matrix = new double[ n ][ n ];
copyMatrix( rotationMatrix, matrix );
return matrix;
}
public void setRotationMatrix( final double[][] matrix )
{
copyMatrix( matrix, rotationMatrix );
invertMatrix( this.rotationMatrix, this.inverseRotationMatrix );
updateBoundingBox();
}
private void copyMatrix( final double[][] source, final double[][] target )
{
for ( int d = 0; d < n; d++ )
{
System.arraycopy( source[ d ], 0, target[ d ], 0, n );
}
}
/**
* internal handler to initialize a rotation corresponding to a null
* transform
*/
private void initializeIdentityTransformationMatrix()
{
rotationMatrix = new double[ n ][ n ];
inverseRotationMatrix = new double[ n ][ n ];
for ( int d = 0; d < n; d++ )
{
rotationMatrix[ d ][ d ] = 1;
inverseRotationMatrix[ d ][ d ] = 1;
}
}
/**
* invert a matrix
*
* @param source
* matrix to invert
* @param target
* matrix to write the result to
*/
private void invertMatrix( final double[][] source, final double[][] target )
{
final Matrix m = new Matrix( source );
final double[][] temp = m.inverse().getArray();
for ( int i = 0; i < n; i++ )
{
System.arraycopy( temp, 0, target, 0, n );
}
}
@Override
public RealRandomAccess< BoolType > realRandomAccess()
{
@@ -243,59 +142,6 @@ private void invertMatrix( final double[][] source, final double[][] target )
@Override
public abstract boolean contains( RealLocalizable l );
/**
* Translate a position in space. Target and source may point to the same
* object.
*
* @param source
* position to move
* @param target
* position to write the result to.
* @param translationVector
* vector the position should be moved by.
* @param prefactor
* scalar the translation will be multiplied with. By setting
* prefactor = -1, the translation direction can easily be
* inverted.
*/
final protected void translate( final double[] source, final double[] target, final double[] translationVector, final double prefactor )
{
for ( int td = 0; td < n; td++ )
{
target[ td ] = source[ td ] + prefactor * translationVector[ td ];
}
}
/**
* rotate a vector using a rotationMatrix. Target and source should not
* point to the same object.
*
* @param source
* vector to rotate
* @param target
* vector to write the result to
* @param rotationMatrix
* n times n matrix describing the rotation
*/
final protected void rotate( final double[] source, final double[] target, final double[][] rotationMatrix )
{
// assert source.length >= 3 && target.length >= 3: "3d affine
// transformations can be applied to 3d coordinates only.";
/*
* source and target may be the same vector, so do not write into target
* before done with source
*/
for ( int td = 0; td < n; td++ )
{
target[ td ] = 0;
for ( int sd = 0; sd < n; sd++ )
{
target[ td ] += source[ sd ] * rotationMatrix[ td ][ sd ];
}
}
}
@Override
public AbstractGeometricShape copyContains()
{
@@ -11,13 +11,13 @@
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -93,115 +93,30 @@ public HyperEllipsoid( final RealLocalizable center, final double[] semiAxisLeng
this.exponent = exponent;
}
/**
* Initialize the ellipse with
*
* @param center
* @param semiAxisLengths
* @param rotationMatrix
*/
public HyperEllipsoid( final RealLocalizable center, final double[] semiAxisLengths, final double[][] rotationMatrix )
{
super( center, semiAxisLengths, rotationMatrix );
}
/**
* Initialize the ellipse with
*
* @param center
* @param semiAxisLengths
* @param rotationMatrix
*/
public HyperEllipsoid( final RealLocalizable center, final double[] semiAxisLengths, final double[][] rotationMatrix, final double exponent )
{
super( center, semiAxisLengths, rotationMatrix );
this.exponent = exponent;
}
/**
* This function determines if a position is inside the cuboid or not.
*/
@Override
public boolean contains( final RealLocalizable l )
{
final double[] questionablePosition = new double[ n ];
l.localize( questionablePosition );
final double[] temp = new double[ n ];
translate( questionablePosition, temp, position, -1 );
rotate( temp, questionablePosition, inverseRotationMatrix );
double distancePowered = 0;
for ( int d = 0; d < n; d++ )
{
distancePowered += Math.pow( Math.abs( ( questionablePosition[ d ] ) / semiAxisLengths[ d ] ), exponent );
distancePowered += Math.pow( Math.abs( ( l.getDoublePosition( d ) - position[ d ] ) / semiAxisLengths[ d ] ), exponent );
}
return ( distancePowered <= 1.0 );
}
/**
* Internal handler to update the bounding box. The bounding box is
* determined by translating/rotating all corner points of the cuboid in
* space (as configured) and afterwards determining minimum and maximum
* coordinates in all dimensions.
*
* TODO: The implementation presented here is taken from a hyperrectangle.
* It should be reprogrammed to match the hyperellipsoid, because the
* bounding box of it may be smaller in fact.
* Internal handler to update the bounding box.
*/
@Override
protected void updateBoundingBox()
{
// there are n*8 points defining minimum and maximum positions. each of
// them has n scalars:
final double[][] boundingBoxPositions = new double[ ( int ) Math.pow( 2, n ) ][ n ];
// initialize position
for ( int d = 0; d < n; d++ )
{
min[ d ] = 0;
max[ d ] = 0;
}
for ( int i = 0; i < boundingBoxPositions.length; i++ )
{
for ( int d = 0; d < n; d++ )
{
if ( ( i & ( 1 << d ) ) > 0 )
{
boundingBoxPositions[ i ][ d ] = semiAxisLengths[ d ];
}
else
{
boundingBoxPositions[ i ][ d ] = -semiAxisLengths[ d ];
}
}
}
// rotate them as configured
for ( int i = 0; i < boundingBoxPositions.length; i++ )
{
final double[] temp = new double[ n ];
this.rotate( boundingBoxPositions[ i ], temp, inverseRotationMatrix );
for ( int d = 0; d < n; d++ )
{
if ( min[ d ] > temp[ d ] )
{
min[ d ] = temp[ d ];
}
if ( max[ d ] < temp[ d ] )
{
max[ d ] = temp[ d ];
}
}
}
// determine minimum and maximum coordinates in all dimensions
for ( int d = 0; d < n; d++ )
{
min[ d ] += position[ d ];
max[ d ] += position[ d ];
min[ d ] = -semiAxisLengths[ d ] + position[ d ];
max[ d ] = semiAxisLengths[ d ] + position[ d ];
}
}
@@ -213,13 +128,12 @@ public double getExponent()
public void setExponent( final double exponent )
{
this.exponent = exponent;
updateBoundingBox();
}
public HyperEllipsoid copy()
{
return new HyperEllipsoid( new RealPoint( position ), semiAxisLengths, rotationMatrix, exponent );
return new HyperEllipsoid( new RealPoint( position ), semiAxisLengths, exponent );
}
}
Oops, something went wrong.

0 comments on commit 37e5efb

Please sign in to comment.