# [Insight-users] rotation

LaMoOsH .. xlolla28x at hotmail.com
Fri Apr 22 18:23:18 EDT 2011

```Hello,

i m wondering if im using the right code to do what i want to do.

i want to used a rotation matrix on my image to rotate my vector over a point. not sure if this is the right code to use. im not specifiying my vector in this code.
it just take a point as an input, which made me feel like there is something wrong. Is there an easier way to do this? is there a better alternative?

Here is the code,

const double epsilon = 1e-10;
const unsigned int N = 2;
bool Ok = true;
typedef itk::Euler2DTransform<double> EulerTransformType;
EulerTransformType::Pointer eulerTransform = EulerTransformType::New();

// Testing Identity
std::cout << "Testing identity transform: ";
eulerTransform->SetIdentity();
EulerTransformType::OffsetType offset = eulerTransform->GetOffset();
if( offset[0] != 0.0
|| offset[1] != 0.0
)
{
std::cout << "[ FAILED ]" << std::endl;
return EXIT_FAILURE;
}
std::cout << "[ PASSED ]" << std::endl;

const double angle = 10.0 * vcl_atan( 1.0f ) / 45.0;
const double sinth = vcl_sin( angle );
const double costh = vcl_cos( angle );

std::cout << "Testing Rotation:";
eulerTransform->SetRotation(angle);

EulerTransformType::InputPointType::ValueType pInit[2] = {10,10};
EulerTransformType::InputPointType p = pInit;
EulerTransformType::InputPointType q;
q[0] = p[0] * costh - p[1] * sinth;
q[1] = p[0] * sinth + p[1] * costh;
EulerTransformType::OutputPointType r;
r = eulerTransform->TransformPoint( p );
for(unsigned int i=0; i<N; i++)
{
if( vcl_fabs( q[i]- r[i] ) > epsilon )
{
Ok = false;
break;
}
}
if( !Ok )
{
std::cerr << "Error rotating point : " << p << std::endl;
std::cerr << "Result should be : " << q << std::endl;
std::cerr << "Reported Result is : " << r << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << " [ PASSED ] " << std::endl;
}

Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110422/fac5f45d/attachment.htm>
```