How to create a random 3d point cloud
이전 댓글 표시
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
Andreas Dorner
2019년 5월 8일
Probably not what you want, but random:
size = 10;
nPoints = 1000;
vars = rand(nPoints, 3)*size;
pc = pointCloud(vars)
julio cruz
2020년 4월 13일
Is there a way to create a random 3D point cloud but have it be within some other point cloud that has the shape of a cube?
darova
2020년 4월 13일
Can you make a sketch or drawing?
julio cruz
2020년 4월 14일
편집: darova
2020년 4월 14일
Attached is the cuboid created in matlab and the data points used. Also, here is the code i used:
dataset = xlsread('data.xlsx','Sheet1','a1:c25');
x = dataset(:,1);
y = dataset(:,2);
z = dataset(:,3);
t=[x y z];
ptCloud = pointCloud(t);
pcshow(ptCloud)
darova
2020년 4월 14일
I draw your data

So you want to draw random 3D curve. What happens if the curve hits the boundaries of this 'cube'?
julio cruz
2020년 4월 15일
the curve cannot go past the boundaries of the cube
darova
2020년 4월 15일
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
2020년 4월 15일
Surprised no one is trying spline(). ?
답변 (1개)
Image Analyst
2020년 4월 15일
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:


카테고리
도움말 센터 및 File Exchange에서 Point Cloud Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!