Set up linear programming code in Matlab to obtain vertices in 4D or higher dimensions

若如初见. 提交于 2019-12-06 11:14:09

The following uses a RANSAC-approach to fit 2D planes onto a nD point cloud. Afterwards the vertices can be found via intersection of those planes.

Algorithmic idea:

The general idea of RANSAC is really simple.

  1. Select random data points called hypothetical inliers
  2. Generate model from hypothetical inliers
  3. Find other points that fit the model well, call them consensus set
  4. Repeat steps 1-3 until having found a model with consensus set of desired magnitude.
  5. Improve the model based on the maximum consensus set.

In our example, we can use it in the following way:

  1. Select three hypothetical inliers.
  2. The plane spanned by those three points is our model.
  3. Compute orthogonal distance of the entire datasets' points to the plane. Select those points within a predefined tolerance.
  4. Repeat steps 1-3 and select the plane with the largest consensus set.
  5. (We could find a least squares fit for the plane now, but in this case that doesn't seem necessary.)
  6. Save the found plane and remove its consensus set from the points we need to search.
  7. Repeat above steps until all planes are found.
  8. Intersect the planes to get the vertices.

Code needed to implement this:

We need a bit of code to achieve this, which is beyond the scope of this answer:

Implementation:

With this the RANSAC part is pretty simple:

%% // Match planes to dataset X:
%  // Choose 3 Points randomly. Generate plane. Find points within tol.
pointsWithinTolOf = @(Points,tol,Space) ...
                      distancePointsAffineSpace(Points, Space)<tol;
availablePoints = 1:size(X,1);
[foundPlane, pointsOfPlane] = deal(cell(0));
for i = 1:maxNumPlanes
    disp(['Plane #',num2str(i)]);
    bestNumInliers = 0;
    for j = 1:numIterations
        randomPointsIdxs = availablePoints(randperm(numel(availablePoints),3));
        currentPlane = X(randomPointsIdxs,:);
        inliers = find(pointsWithinTolOf(X, PointPlaneDistTol, currentPlane));
        numInliers = numel(inliers);
        if numInliers > bestNumInliers
            bestCurrentPlane = currentPlane;
            bestInliers = inliers;
            bestNumInliers = numInliers;
        end
    end
    foundPlane{i} = bestCurrentPlane;
    pointsOfPlane{i} = bestInliers;
    availablePoints = setdiff(availablePoints, bestInliers);
    if isempty(availablePoints)
        break;
    end
end
numPlanes = numel(foundPlane);

The rest of the code is rather long, so I will just write down the basic idea and link to the code.

Once we have found our model planes we:

  • Find the edges of each plane by intersecting all model planes and checking if there are data points on the intersection line.
  • Compute the vertices of each plane by intersecting its edges.

You can download the entire code for this here.

Visualization:

It seems you are dealing with the boundary of a 3D Möbius strip made from three extruded triangles and three extruded quadrangles. Here is a 4D rotation of this strip projected into 3D (projected on your 2D screen.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!