how could i scan a curve and get a surface while i use an n*n*n matrix to represent a space?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
Sean de Wolski
2012년 1월 20일
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.
채택된 답변
Anton Semechko
2012년 1월 22일
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
추가 답변 (2개)
Anton Semechko
2012년 1월 21일
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
2012년 1월 21일
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
Anton Semechko
2012년 1월 21일
.. 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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!