Problem with Patch, trying to fill a surface based on points.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I got an output of a few X Y and Z points, which I want to create into a patch object.
The output however, is more like a sliced potato.
Copy the code below, note that only the last bit about XXX, YYY and ZZZ give the coordinates. any idea how to create a nice consistent shape?
Thanks in advance guys!
PS; Related question; How can I plot a patch object? Say I created a patch object A=patch(x,y,z,1)
Now, after editing it (A.Vertices=[..,..,..]) I want to plot the object in figure(X). What would be the command to get it there?
clc;clear all;close all
r=20;
x=4;
y=6;
z=8;
x0=3;
y0=8;
z0=8;
FOV=pi;
x1=[ x/(x^2 + y^2 + z^2)^(1/2), y/(x^2 + y^2 + z^2)^(1/2), z/(x^2 + y^2 + z^2)^(1/2)]; %<--klopt.
yz=null(x1).'; %find the null spaces of normalised V
xyz=[x1;yz]; %The rows of this matrix are the axes of a normalised
U=xyz(2,:)';
W=xyz(3,:)';%U and W are a ortogonal normal basis for normalised A
a=U(1);b=U(2);c=U(3);d=W(1);e=W(2);f=W(3);
n=1;
tic
for FOV=0:0.1*pi:FOV
for alpha=0:0.2*pi:2*pi
XXX(n)=x0 - ((x/(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*(d*cos(alpha) + a*sin(alpha)))*(a*d*x*x0 + a*d*y*y0 + a*d*z*z0 - a*d*(abs(y + tan(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(z + tan(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(a*d*x + a*tan(FOV/2)*cos(conj(alpha))*abs(d)^2*(x^2 + y^2 + z^2)^(1/2) + d*tan(FOV/2)*sin(conj(alpha))*abs(a)^2*(x^2 + y^2 + z^2)^(1/2))^2/(abs(a)^2*abs(d)^2*(x^2 + y^2 + z^2)))^(1/2)*(x^2 + y^2 + z^2)^(1/2)*(r^2 - x0^2 - y0^2 - z0^2 + (abs(a)^2*abs(d)^2*(a*d*x*x0*cos(FOV/2) + a*d*y*y0*cos(FOV/2) + a*d*z*z0*cos(FOV/2) + a*x0*sin(FOV/2)*cos(conj(alpha))*abs(d)^2*(x^2 + y^2 + z^2)^(1/2) + d*x0*sin(FOV/2)*sin(conj(alpha))*abs(a)^2*(x^2 + y^2 + z^2)^(1/2) + a*d*y0*sin(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + a*d*z0*sin(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + a*d*y0*sin(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2) + a*d*z0*sin(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2))^2)/(a^2*d^2*(abs(a*d*x*cos(FOV/2) + a*sin(FOV/2)*cos(conj(alpha))*abs(d)^2*(x^2 + y^2 + z^2)^(1/2) + d*sin(FOV/2)*sin(conj(alpha))*abs(a)^2*(x^2 + y^2 + z^2)^(1/2))^2 + abs(y*cos(FOV/2) + sin(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + sin(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2))^2*abs(a)^2*abs(d)^2 + abs(z*cos(FOV/2) + sin(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + sin(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2))^2*abs(a)^2*abs(d)^2)))^(1/2) + a*x0*tan(FOV/2)*cos(conj(alpha))*abs(d)^2*(x^2 + y^2 + z^2)^(1/2) + d*x0*tan(FOV/2)*sin(conj(alpha))*abs(a)^2*(x^2 + y^2 + z^2)^(1/2) + a*d*y0*tan(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + a*d*z0*tan(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + a*d*y0*tan(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2) + a*d*z0*tan(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2)))/(a*d*(abs(y + tan(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(z + tan(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(a*d*x + a*tan(FOV/2)*cos(conj(alpha))*abs(d)^2*(x^2 + y^2 + z^2)^(1/2) + d*tan(FOV/2)*sin(conj(alpha))*abs(a)^2*(x^2 + y^2 + z^2)^(1/2))^2/(abs(a)^2*abs(d)^2*(x^2 + y^2 + z^2)))*(x^2 + y^2 + z^2)^(1/2));
YYY(n)= y0 - ((y/(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*(e*cos(alpha) + b*sin(alpha)))*(b*e*x*x0 + b*e*y*y0 + b*e*z*z0 - b*e*(abs(x + tan(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(z + tan(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(b*e*y + b*tan(FOV/2)*cos(conj(alpha))*abs(e)^2*(x^2 + y^2 + z^2)^(1/2) + e*tan(FOV/2)*sin(conj(alpha))*abs(b)^2*(x^2 + y^2 + z^2)^(1/2))^2/(abs(b)^2*abs(e)^2*(x^2 + y^2 + z^2)))^(1/2)*(x^2 + y^2 + z^2)^(1/2)*(r^2 - x0^2 - y0^2 - z0^2 + (abs(b)^2*abs(e)^2*(b*e*x*x0*cos(FOV/2) + b*e*y*y0*cos(FOV/2) + b*e*z*z0*cos(FOV/2) + b*y0*sin(FOV/2)*cos(conj(alpha))*abs(e)^2*(x^2 + y^2 + z^2)^(1/2) + e*y0*sin(FOV/2)*sin(conj(alpha))*abs(b)^2*(x^2 + y^2 + z^2)^(1/2) + b*e*z0*sin(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2) + b*e*x0*sin(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + b*e*z0*sin(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + b*e*x0*sin(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2)/(b^2*e^2*(abs(b*e*y*cos(FOV/2) + b*sin(FOV/2)*cos(conj(alpha))*abs(e)^2*(x^2 + y^2 + z^2)^(1/2) + e*sin(FOV/2)*sin(conj(alpha))*abs(b)^2*(x^2 + y^2 + z^2)^(1/2))^2 + abs(x*cos(FOV/2) + sin(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + sin(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2*abs(b)^2*abs(e)^2 + abs(z*cos(FOV/2) + sin(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + sin(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2))^2*abs(b)^2*abs(e)^2)))^(1/2) + b*y0*tan(FOV/2)*cos(conj(alpha))*abs(e)^2*(x^2 + y^2 + z^2)^(1/2) + e*y0*tan(FOV/2)*sin(conj(alpha))*abs(b)^2*(x^2 + y^2 + z^2)^(1/2) + b*e*z0*tan(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2) + b*e*x0*tan(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + b*e*z0*tan(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + b*e*x0*tan(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2)))/(b*e*(abs(x + tan(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(z + tan(FOV/2)*cos(conj(alpha))*conj(f)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(c)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(b*e*y + b*tan(FOV/2)*cos(conj(alpha))*abs(e)^2*(x^2 + y^2 + z^2)^(1/2) + e*tan(FOV/2)*sin(conj(alpha))*abs(b)^2*(x^2 + y^2 + z^2)^(1/2))^2/(abs(b)^2*abs(e)^2*(x^2 + y^2 + z^2)))*(x^2 + y^2 + z^2)^(1/2));
ZZZ(n)= z0 - ((z/(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*(f*cos(alpha) + c*sin(alpha)))*(c*f*x*x0 + c*f*y*y0 + c*f*z*z0 - c*f*(abs(x + tan(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(y + tan(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(c*f*z + c*tan(FOV/2)*cos(conj(alpha))*abs(f)^2*(x^2 + y^2 + z^2)^(1/2) + f*tan(FOV/2)*sin(conj(alpha))*abs(c)^2*(x^2 + y^2 + z^2)^(1/2))^2/(abs(c)^2*abs(f)^2*(x^2 + y^2 + z^2)))^(1/2)*(x^2 + y^2 + z^2)^(1/2)*(r^2 - x0^2 - y0^2 - z0^2 + (abs(c)^2*abs(f)^2*(c*f*x*x0*cos(FOV/2) + c*f*y*y0*cos(FOV/2) + c*f*z*z0*cos(FOV/2) + c*z0*sin(FOV/2)*cos(conj(alpha))*abs(f)^2*(x^2 + y^2 + z^2)^(1/2) + f*z0*sin(FOV/2)*sin(conj(alpha))*abs(c)^2*(x^2 + y^2 + z^2)^(1/2) + c*f*y0*sin(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2) + c*f*x0*sin(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + c*f*y0*sin(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + c*f*x0*sin(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2)/(c^2*f^2*(abs(c*f*z*cos(FOV/2) + c*sin(FOV/2)*cos(conj(alpha))*abs(f)^2*(x^2 + y^2 + z^2)^(1/2) + f*sin(FOV/2)*sin(conj(alpha))*abs(c)^2*(x^2 + y^2 + z^2)^(1/2))^2 + abs(x*cos(FOV/2) + sin(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + sin(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2*abs(c)^2*abs(f)^2 + abs(y*cos(FOV/2) + sin(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + sin(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2))^2*abs(c)^2*abs(f)^2)))^(1/2) + c*z0*tan(FOV/2)*cos(conj(alpha))*abs(f)^2*(x^2 + y^2 + z^2)^(1/2) + f*z0*tan(FOV/2)*sin(conj(alpha))*abs(c)^2*(x^2 + y^2 + z^2)^(1/2) + c*f*y0*tan(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2) + c*f*x0*tan(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + c*f*y0*tan(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + c*f*x0*tan(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2)))/(c*f*(abs(x + tan(FOV/2)*cos(conj(alpha))*conj(d)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(a)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(y + tan(FOV/2)*cos(conj(alpha))*conj(e)*(x^2 + y^2 + z^2)^(1/2) + tan(FOV/2)*sin(conj(alpha))*conj(b)*(x^2 + y^2 + z^2)^(1/2))^2/(x^2 + y^2 + z^2) + abs(c*f*z + c*tan(FOV/2)*cos(conj(alpha))*abs(f)^2*(x^2 + y^2 + z^2)^(1/2) + f*tan(FOV/2)*sin(conj(alpha))*abs(c)^2*(x^2 + y^2 + z^2)^(1/2))^2/(abs(c)^2*abs(f)^2*(x^2 + y^2 + z^2)))*(x^2 + y^2 + z^2)^(1/2));
n=n+1;
end
end
Patch=patch(XXX,YYY,ZZZ,1)
4 Commenti
Risposta accettata
Più risposte (1)
pfb
il 29 Apr 2015
Not sure you can do that with the patch command "as it is".
You have to create some sort of mesh.
Something nicer is obtained with trisurf or trimesh.
tri = delaunay(XXX,YYY);
trisurf(tri,XXX,YYY,ZZZ);
It's not optimal yet, but I guess it is closer to what you actually want. I think it's also a matter of ordering of the points.
Vedere anche
Categorie
Scopri di più su Polygons in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!