Hello. I have a shape that I would like to cut out a slice of. I also have coordinates from an XY plane at a particular Z value that I'd like to use. So because I'm expecting 2 circles, I calculate their radii and see if my XY plane coordinates match up. However, I'm not getting any good results...is there a better way to do this
This is my shape
This is the way the slice is supposed to look (but upside down)
This is what I'm getting. So my result is suposed to be a 64 by 64 double image. The reason my shape is to the left is because my coordinates also contain negative values. My shape is in the positive side.
This is what my code looks like to make the slice. X_pixels, Y_pixels etc are the coordinates I'm checking.

6 件のコメント

Matt J
Matt J 2021 年 4 月 18 日
編集済み: Matt J 2021 年 4 月 18 日
Where did the surface triangulation originate from? Maybe it would be easier to triangulate the slice than to slice the triangulation.
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 18 日
Hello...I don't understand what you mean.
Matt J
Matt J 2021 年 4 月 18 日
How did you generate the first figure, with the two triangulated spheres? What original data was it derived from?
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 18 日
It was from the orginal shape. I used contours at the Z value I wanted.
I know I can do it this way but I want to use the coordinates of my XY plane
Matt J
Matt J 2021 年 4 月 18 日
編集済み: Matt J 2021 年 4 月 18 日
Please post code in the form of text (in a code-well like the one below) rather than as an image. It makes it easier for us to copy/paste/run.
[X,Y,Z]=sphere;
X_axis=X*2
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 19 日
oh I'm sorry

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2021 年 4 月 18 日
編集済み: Matt J 2021 年 4 月 18 日

0 投票

It seems like it would be better if you would just generate your spheres direclty as a 3D image volume. Then you could just use the slice() commnd to get get the slice images that you want.
xl=(-3:.03:3);
[yl,zl]=deal((-2:0.03:2));
[X,Y,Z]=ndgrid( xl,yl,zl);
Spheres=((X+1.1).^2+Y.^2+Z.^2)<=2^2 | (X-1.1).^2 + Y.^2 +Z.^2<=2^2;
imshow(Spheres(:,:,20).');

10 件のコメント

Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 19 日
What if I want to show the part of the image that intersects
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 19 日
And please can you explain the code more. I'm new to matlab so it is a bit unfamiliar
Matt J
Matt J 2021 年 4 月 19 日
This will show the intersection:
xl=(-3:.03:3);
[yl,zl]=deal((-2:0.03:2));
[X,Y,Z]=ndgrid( xl,yl,zl);
Spheres=(((X+1.1).^2+Y.^2+Z.^2)<=2^2) + ((X-1.1).^2 + Y.^2 +Z.^2<=2^2);
imagesc(Spheres(:,:,20).'); axis image; colormap(gray)
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 19 日
編集済み: Nnebunne Melisa 2021 年 4 月 19 日
Please can you explain the last two lines of code. From " spheres = ..."
Also What if I want to visualize the "spheres" shape in 3d?
Matt J
Matt J 2021 年 4 月 19 日
編集済み: Matt J 2021 年 4 月 19 日
Please can you explain the last two lines of code. From " spheres = ..."
Well, the region of a sphere satisfies the inequality . We've simply used that inequality to create two binary image volumes containing spheres at different center locations and added them together.
Also What if I want to visualize the "spheres" shape in 3d?
You've already done that in the mesh plot you posted. But you can also use volumeViewer or volshow().
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 20 日
what of the last sentence "Imshow..."
Matt J
Matt J 2021 年 4 月 20 日
It just displays Spheres(:,:,20).'
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 21 日
why does the z say 20? The axis is not up to 20. And why does it end with " .' "?
I'm sorry for all the questions. I'm just trying to understand
Matt J
Matt J 2021 年 4 月 21 日
編集済み: Matt J 2021 年 4 月 21 日
It's a 3D array with 134 slices.
whos Spheres
Name Size Bytes Class Attributes Spheres 201x134x134 3609156 logical
I just picked the 20th slice arbitrarily. The .' transposes the slice, so that it's longest side is displayed horizontally, but you don't have to do that if you prefer to view the untransposed slice.
Nnebunne Melisa
Nnebunne Melisa 2021 年 4 月 23 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by