# Plane Fitting with vtk

**URL:** https://discourse.vtk.org/t/plane-fitting-with-vtk/5196
**Category:** Support
**Tags:** doxygen, jobs, training, proposal, file-formats
**Created:** [February 15, 2021, 11:54pm UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196 "2021-02-15T23:54:23Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [February 15, 2021, 11:54pm UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/1 "2021-02-15T23:54:24Z")

</div>

Hello

I want to implement Plane Fitting using vtk.  
Can I get some information for your reference?

I’m always getting your help.  
Thank you.

BR

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [February 16, 2021, 12:21am UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/2 "2021-02-16T00:21:14Z")

</div>

There are many ways to fit a plane (least squares, RANSAC, …). Can you write more about your requirements?

Do you build VTK from source or you use it from Python?

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [February 16, 2021, 12:25am UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/3 "2021-02-16T00:25:44Z")

</div>

Here is one available method: [vtkPlane::ComputeBestFittingPlane](https://vtk.org/doc/nightly/html/classvtkPlane.html#a7b88495d93a5aa5053b1044965df67bd)

---

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [February 16, 2021, 1:51am UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/4 "2021-02-16T01:51:10Z")

</div>

I am using vtk and I am in Visual Studio 2015 C++ environment.

---

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [February 16, 2021, 1:54am UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/5 "2021-02-16T01:54:52Z")

</div>

Thank you for answer.  
I’ll try searching.

Is it suitable for plane correction of 3D data~?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 16, 2021, 8:44pm UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/6 "2021-02-16T20:44:09Z")

</div>

Hello,

By “plane correction” do you mean this (undo lens distortions):

 ![image](https://discourse.vtk.org/uploads/default/original/2X/7/7e6b2b11ea32236e9b0d177f821d5065782f66a5.png)  
or this (undo perspective projection):  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5137b384e43f500bd1fa1f695c1d5d1862cdd157.jpeg)  
?

cheers,

Paulo

---

<div class="post-metadata">

### Author: ![Seram](https://discourse.vtk.org/user_avatar/discourse.vtk.org/seram/32/1783_2.png) [@Seram](https://discourse.vtk.org/u/Seram)
#### Post date: [February 17, 2021, 2:02am UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/8 "2021-02-17T02:02:53Z")

</div>

As shown in the attached image,  
Align the left and right sides and top and bottom with the same surface as possible.

I want to make it work like this:

Example) CloudCompare

1. Tools -\> Fit -\> Plane (Get Matrix 4x4)
2. Edit -\> Apply Transformaction (Set Matrix 4x4)

 ![이미지 1216](https://discourse.vtk.org/uploads/default/original/2X/8/8de29cbeff71d3418393e65fbd931c2fd4ceb2ed.jpeg)

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 17, 2021, 12:23pm UTC](https://discourse.vtk.org/t/plane-fitting-with-vtk/5196/9 "2021-02-17T12:23:30Z")

</div>

If your data is supposed to represent a functional surface ( e.g. a height map where z = f(x, y) ), then it is not a good idea to apply a rotation to your points towards the fitted plane. Why? Because you will change the (x, y) coordinates too.

What you want is tecnically not a correction but an operation called detrending. Detrending alone is an entire field of research. **Assuming your data is functional** , a simple and fast procedure is: a) fit a plane like you suggested; b) evaluate the slope function at each data location (z\* = f(x, y)); c) then making a new z for each data point z’ = z - z\*.
