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)
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
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.
Jianwei Guo
Jianwei Guo on 21 Jan 2012
Thank you very much, Sean.
For example: k=zeros(3, 3, 3), each element in k represents a cubic. When I set k(2, 1, 1)=1 and k(3, 2, 1)=1, we get a line. When I rotate this line around k(3, 2, :) and set elements touched by the line, we get a surface and now k(:, :, 1)=[1, 1, 1;1, 1, 1;0, 1, 0].

Sign in to comment.

Accepted Answer

Anton Semechko
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

More Answers (2)

Anton Semechko
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
  1 Comment
Jianwei Guo
Jianwei Guo on 22 Jan 2012
Thank you very much, Anton.
I can see that this function will do the job. While, sometimes the rotate-axis may not be parallel with either x- or y-axis, and there may be limitation in range of rotating angle. How could these two problem be solved? It confuses me very much while I hope the rotation of a surface be done in the shortest time.
By the way, what do you mean by tetra mesh? It's the first time I heard that, and seems different from mesh or surf while they are just used to show a surface.

Sign in to comment.


Anton Semechko
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
Jianwei Guo
Jianwei Guo on 21 Jan 2012
I understand your confusion. While mesh is an easy way to show a surface, its precise also depends on data I provide. Actually, I want to use 3D matrix to represent a space, then to draw a curve, rotate the curve to get a surface and then rotate the surface to get a solid object. As I have not find proper function to do this, 3D matrix seems the only choice, so…
Anton Semechko
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!