how could i scan a curve and get a surface while i use an n*n*n matrix to represent a space?
3 views (last 30 days)
Show older comments
i want to use a matrix of 100*100*100 to represent a space, and each dimension represent a range of x, y or z. Each element could be 1 or 0, 1 means that point is occupied, thus i can drew a curve in that space now----when i have the function of the curve and use small step size to evaluate it, those points occupied in the matrix can be told, and it's easy. What confuses me is how to scan a curve in the matrix to get a surface when the curve rotates with an axis may not align with x-, y- or z-axis. One way is to rotate with small degree step, but there is probability that some points should be occupied may be overcome. Also, it takes longer then expected. It's a rough method to use 3D-matrix, compared to many professional software such as SOLIDWORKS, but it really matters to me. Any suggestion would be helpful and thanks very much.
2 Comments
Sean de Wolski
on 20 Jan 2012
I do not understand what you want. Could you provide a small example, perhaps with a 3x3x3 matrix. Please provide: input data, operations, expected output data.
Accepted Answer
Anton Semechko
on 22 Jan 2012
1) To get the surface of revolution about some vector not aligned with y-axis, rotate your 2D binary image by that amount. After you get the solid, rotate it back.
2) Tetra mesh = tetrahedral mesh. There are no built in functions in Matlab to generate it, but you can find them if you search the web. Here is one resource: http://iso2mesh.sourceforge.net/cgi-bin/index.cgi
0 Comments
More Answers (2)
Anton Semechko
on 21 Jan 2012
Try this:
function BW=SolidOfRevolution(bw)
% Rotate 2D binary image about the y-axis to get a 3D binary volume.
%
% - bw : M-by-N binary image, where N is an odd integer
% - BW : M-by-N-by-N binary volume obtained by rotating bw about the
% y-axis passing trough the centroid of bw.
% Error checking ----------------------------------------------------------
if ndims(bw)~=2 || ~islogical(bw)
error('Input argumanet must be a 2D binary image')
end
siz=size(bw);
if mod(siz(2),2)==0
error('Input image must have odd number of columns')
end
BW=false([siz,siz(2)]);
if sum(bw(:))==0, return; end
% Fing the solid of revolution --------------------------------------------
Cx=ceil(siz(2)/2); % centroid along the x-axis
% Generate N-by-N latice centered on Cx
[x,y]=meshgrid(-(Cx-1):(Cx-1));
R2=x.^2+y.^2;
R2=permute(R2,[3 2 1]);
% Get the co-ords of foreground pixels
[Y,X]=find(bw);
R=abs(X-Cx);
clear x y X bw
% Generate BW by looping through individual rows of bw
for i=min(Y):max(Y)
% Get the radii of the furthest and closest points
Rmax=max(R(Y==i));
Rmin=min(R(Y==i));
% Read in the i-th sclice
bw=(R2<=Rmax^2) & (R2>=Rmin^2) ;
BW(i,:,:)=bw;
end
Anton Semechko
on 21 Jan 2012
Hi Jianwei, so essentially what you are looking for is a surface of revolution. My question is why do you need an implicit representation of the surface? To me it seems that creating a quad mesh would be much easier ...
3 Comments
Anton Semechko
on 21 Jan 2012
.. and precision of your solid of revolution will depend on the resolution of the 3D lattice you use to discretize it.
Anyway, what I am trying to understand is why you need a solid representaion and why you are going about it in this way? You know you can always convert a surface mesh to tetra mesh, right?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!