How can I generate points (equally distanced) inside a torus volume and send rays from a particular origin to all of the generated points? Similar in the attached picture, but I need to send rays to all of the points. Can anybody please help me out?

7 Ansichten (letzte 30 Tage)

Antworten (1)

John D'Errico
John D'Errico am 13 Jun. 2016
Help you out? Do you want me to write the code? Sorry, but no. That would take too long to do here, all to generate something that exactly emulates something you already apparently have.
Generating points inside a torus is easy enough. The picture shows a fairly random sampling, NOT equally spaced. But perhaps you mean uniformly random. Just generate them using a rejection method. Use a uniform sampling, then discard any that fall outside the torus. (This is simpler than a constructive sampling inside a toroidal coordinate system of some sort, or sampling in cylindrical coordinates. In 3 dimensions, rejection sampling will be entirely adequate.)
The use either plot or line to draw the "rays".
help plot
help line
You can use mesh or surf to draw a torus. Start with meshgrid, where the two variables will be interpreted as angles, from 0-360 degrees. Then transform them into a torus. Just spatial geometry there.
help meshgrid
help mesh
help surf
Assuming you wish to exactly emulate the figure that you already have (not sure why) then you will probably want to turn off all the axes. Overlay the region of the torus with a grid (again, using line or plot, and then overlay that region only with a semi-transparent gray.
Each step is not that difficult. Yes, it will take some effort if you want to emulate everything there exactly. This is also why I have no interest in doing your work for you, since it would take at least an hour or two to get perfect. And then once I did, you would decide it was not perfect, and could I change something like the view angle, or you would ask for a complete explanation, in depth. (Yeah, like that never happens.) This is why you need to learn to do each step yourself, and understand it all.
The point is, all of the above may SEEM complex, but it is not. Take each step as I have described it in isolation. Figure out how to do each piece of the puzzle. Then put it all together. Eat a computational elephant one byte at a time.

Community Treasure Hunt

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

Start Hunting!

Translated by