How to build a plane passing through 3 points

Hi,
I would like to build a plane knowing only three points. Here is my code, but it dosen’t work can someone help please?
planes = []
planes.append(vtkPlanes())
planes[0].SetPoints(points_bct)
piano_aorta = planes[0].GetPlane(0)
The problem is that pianoaorta is empty

Welcome to VTK, @ioneianni !

I don’t believe vtkPlanes will compute a plane the way you want it to. You’ll instead have to supply an origin point and a normal to define the plane yourself. Fortunately, this isn’t too difficult.

Select one of your points {p1, p2, p3} as the plane’s Origin. Let’s say you pick p1. Now, compute two vectors v1 and v2 from the other two points by subtracting p1 from those points. Normalize the vectors. Finally, find the cross product of the normalized vectors to give you a normal.

In VTK code, you can do this with

from vtk import vtkMath
p1  = your first point. Could be list or tuple
p2 =
p3 =
v1 = [0, 0, 0] # make it a list because a list is assignable
v2 = [0, 0, 0]
normal = [0, 0, 0]
vtkMath::Subtract(p2, p1, v1);
vtkMath::Normalize(v1);
vtkMath::Subtract(p3, p1, v2);
vtkMath::Normalize(v2);
vtkMath::Cross(v1, v2, normal);

Now you can define a plane with something like

planes[0].SetNumberOfPlanes(1)
plane = planes[0].GetPlane(0)
plane.SetOrigin(p1)
plane.SetNormal(normal)

Hope that helps!

1 Like

Thanks, for your answer!