# Calculation of 4x4 matrix of planes

**URL:** https://discourse.vtk.org/t/calculation-of-4x4-matrix-of-planes/1423
**Category:** Development
**Created:** [July 26, 2019, 11:08am UTC](https://discourse.vtk.org/t/calculation-of-4x4-matrix-of-planes/1423 "2019-07-26T11:08:33Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 29, 2019, 2:19pm UTC](https://discourse.vtk.org/t/calculation-of-4x4-matrix-of-planes/1423/4 "2019-07-29T14:19:54Z")

</div>

The ‘plane[4]’ is the coefficients _a,b,c,d_ for the  
[equation of a plane](https://en.wikipedia.org/wiki/Plane_(geometry)#Point-normal_form_and_general_form_of_the_equation_of_a_plane). It is important to understand that the first three components _a,b,c_ of plane[4] are the normal, so on [line 664](https://en.wikipedia.org/wiki/Plane_(geometry)#Point-normal_form_and_general_form_of_the_equation_of_a_plane) it is possible to say `normal = plane`.

LInes 600 to 630 get the plane (and wplane, which is the plane after the actor transformation from ‘data’ coords to ‘world’ coords). The plane is oriented so that the normal points towards the ‘camera’ (this means it points out of the computer screen, not into the computer screen).

Lines 631 to 642 do exactly what the comment says: find the largest component of the normal. This checks whether the normal is closest to the x, the y, or the z axis.

For your original question, I think it is most important to understand how ‘v1’ and ‘v2’ are computed. Compare this to the simpler (much less general) answer I gave to Post 1391, which computes the matrix only for a rotation around the Z axis:

> [@How to convert the coordinate between pixel and physical (vtkImageReslice)?](https://discourse.vtk.org/t/how-to-convert-the-coordinate-between-pixel-and-physical-vtkimagereslice/1391/4):
>
> ```
> import math
> angle = math.pi/4
> x = [math.cos(angle),math.sin(angle),0.0]
> y = [-math.sin(angle),math.cos(angle),0.0]
> z = [0.0,0.0,1.0]
> # the center of the slice in input coordinates
> center = [255.5, 255.5, 40.0]
> # the center of the slice in output coordinates
> ss = [255.5, 255.5, 0.0]
> axialElement = [
> x[0], y[0], z[0], center[0] - ss[0]*x[0] - ss[1]*y[0] - ss[2]*z[0],
> x[1], y[1], z[1], center[1] - ss[0]*x[1] - ss[1]*y[1] - ss[2]*z[1],
> x[2], y[2], z[2], center[2] - ss[0]*x[2] - ss[1]*y[2] - ss[2]*z[2],
> 0.0, 0.0, 0.0, 1.0 ]
> 
> ```

---

_[View the full topic](https://discourse.vtk.org/t/calculation-of-4x4-matrix-of-planes/1423)._
