assigning a number to a voxel

3 views (last 30 days)
Merisa Saber
Merisa Saber on 9 Apr 2019
Hello
I'm trying to find the places which a line goes through in 3D space. I considered a space with 10 cm length in x, y and z direction which are devided in 10 segment. So, if you consider the space with 10 cm length in each side as a cube then each division is called a voxel (a 3D pixel). I want to assign a number to each voxel and then when a line goes through the space I can find the numbers of voxels which the line passes. I've used another method before and written a code in which I started from a point in lower left of the space and increase it with a distinc step and put each point for example of x in line equation and find other coordinates like y and z then checked whether that y or that z of space is as the same as y and z of line for that specific x or not. I defined a zero matrix with size of the number of space division. and for each voxel that the line goes through, the corresponding element of matrix will change to 1. a part of code is here:
l=[3 5 1 -5 -3 4]; Lx=10; Ly=10; Lz=10; dx=1; dy=1; dz=1; xi=l(:,1); yi=l(:,2); zi=l(:,3);
V=l(:,1:3)-l(:,4:6); a=V(:,1); b=V(:,2); c=V(:,3); xl=-5; yl=-5; zl=-5;
K=0;
K(1:(Lx/dx+1),1:(Ly/dy+1),1:(Lz/dz+1))=0;
for i=1:(Lx/dx+1)
for j=1:(Ly/dy+1)
for k=1:(Lz/dz+1)
x1=xl+(i-1)*dx;
x2=x1+dx;
y1=yl+(j-1)*dy;
y2=y1+dy;
z1=zl+(k-1)*dz;
z2=z1+dz;
if ((b./a).*(x1-xi)+yi)>=y1 & ((b./a).*(x1-xi)+yi)<=y2
if ((c./a).*(x1-xi)+zi)>=z1 & ((c./a).*(x1-xi)+zi)<=z2
K(i,j,k)=1;
end
end
if ............and so on
this code check all points and I'll get a matrix with 0 and 1 elements in which 1 shows the line goes through the corresponding voxel.
But now I think just use the points which obtain from line equation. So first, I want to assign a number to each voxel, then write a code which shows the numbers of voxels which the line goes through. then group the lines with common voxels. I think this method may be faster than my written code. could you help me assign numbers to voxels and write the new code or you think my previous cod is better?

Answers (0)

Community Treasure Hunt

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

Start Hunting!