Conversation
Added the torus surface to this new fork of the dev branch in order to create a draft pull request for the project.
|
Thanks for working on this, @Talen-Ayers ! |
| """ | ||
| Torus: Implicit equation of a torus radially symmetric about the z-axis in the cartesian plane | ||
|
|
||
| r^2 = f(x, y, z) = ( sqrt( (x - A)^2 + (y - B)^2) - R )^2 + (z - C)^2 |
There was a problem hiding this comment.
Should we move the r^2 to the right-hand side to get the conventional behavior of a surface equation? That is:
- f(x,y,z) = 0 --> (x,y,z) is on the torus
- f(x,y,z) < 0 --> (x,y,z) is inside the torus
- f(x,y,z) > 0 --> (x,y,z) is outside the torus
| """ | ||
| Torus: Implicit equation of a torus radially symmetric about the z-axis in the cartesian plane | ||
|
|
||
| r^2 = f(x, y, z) = ( sqrt( (x - A)^2 + (y - B)^2) - R )^2 + (z - C)^2 |
There was a problem hiding this comment.
Should this be the formula for torus-z?
| return INF | ||
|
|
||
| # Using the smallest root to get the value of t at the first point of intersection | ||
| # If the direction vector is normalized, the distance to intersection is just the value of t |
There was a problem hiding this comment.
The direction vector is always normalized.
| # Due to the sqrt in the derivative functions, if the particle is not in the x-y space where the torus has z values, it will result in complex numbers | ||
| # Specificaly the term: math.sqrt(r**2 - (R - inv_root)**2), where inverse root = math.sqrt((A-x)**2 + (B-y)**2) | ||
| @njit | ||
| def get_normal_component(particle_container, surface): |
There was a problem hiding this comment.
Note that, whenever this function is called during the transport, the particle position (x,y,z) would yield
f(x,y,z) = 0.0 +- COINCIDENCE_TOLERANCE (the particle is on the surface, or evaluate ~ 0.0)
| # Due to the sqrt in the derivative functions, if the particle is not in the x-y space where the torus has z values, it will result in complex numbers | ||
| # Specificaly the term: math.sqrt(r**2 - (R - inv_root)**2), where inverse root = math.sqrt((A-x)**2 + (B-y)**2) | ||
| @njit | ||
| def reflect(particle_container, surface): |
There was a problem hiding this comment.
I think it is rare to have a reflecting torus boundary condition. But it would be cool to have it when one needs it!
|
I think the next step would be setting up the unit test. You can check this out as a reference. To manually run the test, we do === As you can see, now there are only tests for axis-aligned planes. Adding unit tests for the other surfaces for warming up would be great if you are interested! 😉 |
Changed the math in the evaluate function to allow the function to be called outside the torus x-y space without throwing an error.
Actually, there is another piece that you need to work on first before setting up the unit test. And that is the torus surface creation. Note that:
In Note that in the creation method, we store the coefficients in A, B, ..., I, J. This means, you would need to re-letter the coefficients that you expect in your functions; for example, changing "r" and "R" into "I" and "J". |
Changed the reflect and get_normal_component functions to use the expanded form of the torus equations. This allows these functions to be called outside the x-y area of the torus.
Imported the torus surface at the top of the file.
• Import the torus constant
• Add the torus function under the surface class
• Add the torus to the decode type function
• Add the radius constants to the super function and surface class
Add the torus surface constant
• Import the torus surface
• Import the torus constant
• add functions (evaluate, normal comp, reflect, get distance)
| Where R is the radius of the shape as a whole, and r is the radius of the circle that is revolved to create the donut | ||
|
|
||
| Removing the square roots leaves you with the following equation: | ||
| f (x, y, z) = ( x^2 + y^2 + z^2 + R^2 - a^2 )^2 - 4R^2 * (x^2 + y^2) |
There was a problem hiding this comment.
f (x, y, z) = ( x^2 + y^2 + z^2 + R^2 - r^2 )^2 - 4R^2 * (x^2 + y^2)
Changing the torus surface name to accurately reflect its geometry from Torus-X to Torus-Z as the torus is radially symmetric around the z-axis.
Fixed typos and removed debug prints from code.
Changed torus name to Torus-z to accurately reflect its geometry.
Changed Torus-x to Torus-Z, see previous commits.
Added a coincident check to the get_distance_function, needs to be tested.
Added the torus surface to this new fork of the dev branch in order to create a draft pull request for the project.