Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That sounds about right, but you should replace the nonlinear optimization with an SVD. The following creates the moment of inertia tensor, M, and then SVD's it to get the normal to the plane. This should be a close approximation to the least-squares fit and be much faster and more predictable. It returns the point-cloud center and the normal.</p> <pre><code>def planeFit(points): """ p, n = planeFit(points) Given an array, points, of shape (d,...) representing points in d-dimensional space, fit an d-dimensional plane to the points. Return a point, p, on the plane (the point-cloud centroid), and the normal, n. """ import numpy as np from numpy.linalg import svd points = np.reshape(points, (np.shape(points)[0], -1)) # Collapse trialing dimensions assert points.shape[0] &lt;= points.shape[1], "There are only {} points in {} dimensions.".format(points.shape[1], points.shape[0]) ctr = points.mean(axis=1) x = points - ctr[:,np.newaxis] M = np.dot(x, x.T) # Could also use np.cov(x) here. return ctr, svd(M)[0][:,-1] </code></pre> <p>For example: Construct a 2D cloud at (10, 100) that is thin in the x direction and 100 times bigger in the y direction:</p> <pre><code>&gt;&gt;&gt; pts = np.diag((.1, 10)).dot(randn(2,1000)) + np.reshape((10, 100),(2,-1)) </code></pre> <p>The fit plane is very nearly at (10, 100) with a normal very nearly along the x axis.</p> <pre><code>&gt;&gt;&gt; planeFit(pts) (array([ 10.00382471, 99.48404676]), array([ 9.99999881e-01, 4.88824145e-04])) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload