# [vtkusers] reslice using an arbitrary orientation

Esmeralda Ruiz esmeralda.ruiz at alma3d.com
Mon Mar 25 19:27:29 EDT 2019

```Dear all

i update the question i wrote wrong the perpendicular making changes
double perpendicular[3] = { vt[0],0,vt[1] };

but i see that even i compute the perpendicular what it gives it is not
what i want. What i want is the slice that intersects in this orientation
not to create a new coordinate using this orientation. Any idea?

thanks

El lun., 25 mar. 2019 a las 20:08, zandarina (<esmeralda.ruiz at alma3d.com>)
escribió:

> Dear all
>
> I want to reslice a 3d volume computing the perpendicular
> between two points x and y. I compute the
> perpendicular berween point 1, point2 in x and y (z is the same for all
> points as the
> poins are obtained of one slice)
>
> And then i compute the perpendicular of x and y
> And i compute the rotation. And i get a blank image. I would like to
> cut the slice cutting through the perpendicular of those two points.
>
> I attach the code. Is there something wrong
>
> Any help?
>
>
>
>   double vt[3];
>         vt[0] = pts2[0] - pts1[0];
>         vt[1] = pts2[1] - pts1[1];
>         vt[2] = pts2[2] - pts1[2]; // it will be 0 as z is the same in all
> points
>         double perpendicular[3] = { -vt[1],vt[0],0 };
>
>         double startPoint[3], endPoint[3];
>         startPoint[0] = tar_cen[0];
>         startPoint[1] = tar_cen[1];
>         startPoint[2] = tar_cen[2];
>         endPoint[0] = startPoint[0] + perpendicular[0];
>         endPoint[1] = startPoint[1] + perpendicular[1];
>         endPoint[2] = startPoint[2] + perpendicular[2];
>
>         // Compute a basis
>         double normalizedX[3];
>         double normalizedY[3];
>         double normalizedZ[3];
>
>         // The X axis is a vector from start to end
>         vtkMath::Subtract(endPoint, startPoint, normalizedX);
>         //double length = vtkMath::Norm(normalizedX);
>         vtkMath::Normalize(normalizedX);
>
>         // The Z axis is an arbitrary vector cross X
>         double arbitrary[3];
>         arbitrary[0] = vtkMath::Random(-10, 10);
>         arbitrary[1] = vtkMath::Random(-10, 10);
>         arbitrary[2] = vtkMath::Random(-10, 10);
>         vtkMath::Cross(normalizedX, arbitrary, normalizedZ);
>         vtkMath::Normalize(normalizedZ);
>
>         // The Y axis is Z cross X
>         vtkMath::Cross(normalizedZ, normalizedX, normalizedY);
>         vtkSmartPointer<vtkMatrix4x4> matrix =
>             vtkSmartPointer<vtkMatrix4x4>::New();
>
>         // Create the direction cosine matrix
>         matrix->Identity();
>         for (unsigned int i = 0; i < 3; i++)
>         {
>             matrix->SetElement(i, 0, normalizedX[i]);
>             matrix->SetElement(i, 1, normalizedY[i]);
>             matrix->SetElement(i, 2, normalizedZ[i]);
>         }
>
>         // Apply the transforms
>         vtkSmartPointer<vtkTransform> transform =
>             vtkSmartPointer<vtkTransform>::New();
>         transform->Translate(startPoint);
>         transform->Concatenate(matrix);
>
>
>
>
>         reslice->SetResliceTransform(transform);
>
>
>         //Step 3: done
>         reslice->Update();
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>