How to create a random 3d point cloud

4 Ansichten (letzte 30 Tage)
Rupert Schaffarz
Rupert Schaffarz am 8 Mai 2019
Beantwortet: Image Analyst am 15 Apr. 2020
Hello
I would like to create a random 3D pointcloud (in the pointcloud format) and then fit a 3D curve (spline) passing through it (randomly).
How is it possible ?
Please help me.
Thank You.
  8 Kommentare
darova
darova am 15 Apr. 2020
I think it's too complicated
If it was a 2D dimensional case i'd just use inpolygon to check if curve is inside the box. But it's 3D
I can't handle it
Do you have any ideas?
Image Analyst
Image Analyst am 15 Apr. 2020
Surprised no one is trying spline(). ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 15 Apr. 2020
Try using spline() on each of x, y, and z separately:
% Initialization steps.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
data = xlsread('data.xlsx')
x = data(:, 1);
y = data(:, 2);
z = data(:, 3);
hFig1 = figure;
plot3(x, y, z, 'b.-', 'MarkerSize', 20, 'LineWidth', 2);
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
zlabel('z', 'FontSize', fontSize);
grid on;
hFig1.WindowState = 'maximized';
% Now spline fit 1000 points in between.
hFig2 = figure;
xq = linspace(1, length(x), 1000);
xs = spline(1:length(x), x, xq);
yq = linspace(1, length(y), 1000);
ys = spline(1:length(y), y, yq);
zq = linspace(1, length(z), 1000);
zs = spline(1:length(z), z, zq);
% Plot them.
subplot(2, 1, 1);
plot(1 : length(x), x, 'r.', 'MarkerSize', 20);
hold on;
plot(1 : length(y), y, 'g.', 'MarkerSize', 20);
plot(1 : length(z), z, 'b.', 'MarkerSize', 20);
title('Original X, Y, and Z Values', 'FontSize', fontSize);
legend('x', 'y', 'z');
subplot(2, 1, 2);
plot(1 : length(xs), xs, 'r-', 'LineWidth', 2);
hold on;
plot(1 : length(ys), ys, 'g-', 'LineWidth', 2);
plot(1 : length(zs), zs, 'b-', 'LineWidth', 2);
grid on;
title('Spline Fits', 'FontSize', fontSize);
legend('x', 'y', 'z');
% Plot back on the main figure in red.
figure(hFig1);
hold on;
plot3(xs, ys, zs, 'r-', 'LineWidth', 2);
% Clip all values to no lower than 0.
xs = max(0, xs);
ys = max(0, ys);
zs = max(0, zs);
% Clip all values to no higher than 1.
xs = min(1, xs);
ys = min(1, ys);
zs = min(1, zs);
% Plot clipped range back on the main figure in magenta.
plot3(xs, ys, zs, 'm-', 'LineWidth', 2);
legend('Original Knots', 'Spline Fit', 'Clipped');
fprintf('Done running %s.m ...\n', mfilename);
In the plot below, the original data is in blue, the spline fit is in red, and the curve clipped to the small box with 0-to-1 range is in magenta:

Kategorien

Mehr zu Smoothing finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by