필터 지우기
필터 지우기

How to create a random 3d point cloud

조회 수: 6 (최근 30일)
Rupert Schaffarz
Rupert Schaffarz 2019년 5월 8일
답변: Image Analyst 2020년 4월 15일
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
darova
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
Image Analyst 2020년 4월 15일
Surprised no one is trying spline(). ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
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:

카테고리

Help CenterFile Exchange에서 Smoothing에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by