I want to fit lines to the 3D points seen in the photo and get its shape But I do not know how to do it. please guide me. The points file is available.

조회 수: 3 (최근 30일)

채택된 답변

darova
darova 2021년 9월 17일
SOmething is wrong with the data you attached
s = importdata('POINT.txt');
x = s(:,1);
y = s(:,2);
z = s(:,3);
plot3(x,y,z,'.-r')
  댓글 수: 4
adel hosseini
adel hosseini 2021년 9월 28일
Thank you in advance for your help
Do you mean that?
clc;
clear;
close all;
S = importdata('POINT2.txt');
x = S(:,1);
y = S(:,2);
z = S(:,3);
points1 = length(S);
randLoc1=randi(points1);
randPoint1(1,:)=S(randLoc1,1:3);
xr=randPoint1(1,1);
yr=randPoint1(1,2);
zr=randPoint1(1,3);
findrand=find(S(:,1)==xr & S(:,3)==zr);
leangthafindrand = size(findrand,1);
class{1}(1:leangthafindrand,:)=S(findrand,1:3);
leangthclass=size(class{1},1);
S(S(:,1)==xr & S(:,3)==zr,:)=[];
x1 = S(:,1);
y1 = S(:,2);
z1 = S(:,3);
plot(xr,zr,'.r','marker','o')
hold on
plot(x1,z1,'.b')
points2 = length(S);
minDis=0;
m=0;
k=1;
while points2>0
m=m+1;
minDis=0;
while minDis<0.8 && points2>0
for i=1:1:points2(1,1);
dis{k}(i)=abs(sqrt((x1(i)-xr)^2 + (z1(i)-zr)^2));
end
minDis=min(dis{k});
aa=find(dis{k}(:)==minDis);
hold on
plot(x1(aa),z1(aa),'.y','marker','o')
leangtha = size(aa,1);
p=leangthclass+leangtha;
class{m}(leangthclass+1:p,:)=S(aa,1:3);
leangthclass=size(class{m},1);
xr=S(aa(1),1);
yr=S(aa(1),2);
zr=S(aa(1),3);
plot(xr,zr,'.r','marker','o')
axis equal
S(S(:,1)==xr & S(:,3)==zr,:)=[];
x1 = S(:,1);
y1 = S(:,2);
z1 = S(:,3);
points2 = size(S,1);
k=k+1;
end
leangthclass=1;
endclass=class{m}(end,:);
findend=find(class{m}(:,1)==endclass(1,1) & class{m}(:,2)==endclass(1,2) & class{m}(:,3)==endclass(1,3));
class{m+1}(1,:)=class{m}(end,:);
class{m}(findend(:),:)=[];
line(class{m}(:,1),class{m}(:,3),'marker','o','linestyle','-')
end
class{m}(end+1,:)=class{m+1}(1,:);
class{m+1}(:,:)=[];
line(class{m}(:,1),class{m}(:,3),'marker','o','linestyle','-')

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by