Open munechika-koyo opened 1 year ago
@vsnever @mattngc @CnlPepper This feature is not prioritized over other issues, but how do you feel about adding this?
I've not had a chance to look at this, but, assuming you haven't, could you make test demo that checks it works correctly with the CSG operations (tests next intersection)?
@CnlPepper I tried to calculate csg oprations by:
I think the implementation of the next_intersection()
method is inconsistent with its intended behaviour. The description of this method says:
https://github.com/raysect/source/blob/20f57259136ded2db692a967e486ebec88066b8a/raysect/core/scenegraph/primitive.pyx#L105-L119
Unlike any other primitive in Raysect, there are up to four possible intersections of a ray with a torus, but the method always stops after the second intersection.
cpdef Intersection next_intersection(self):
if not self._further_intersection:
return None
# this is the 2nd intersection
self._further_intersection = False
return self._generate_intersection(self._cached_ray, self._cached_origin, self._cached_direction, self._next_t)
The method is used only in the CSGPrimitive._identify_intersection()
method.
As a result, extra intersections are generated in some cases. The output of this script:
from raysect.optical import Point3D, Vector3D, World, translate, InterpolatedSF
from raysect.optical.material import Dielectric
from raysect.primitive import Union, Torus, Cylinder
from raysect.optical.loggingray import LoggingRay
glass = Dielectric(index=InterpolatedSF([10, 10000], [1., 1.]),
transmission=InterpolatedSF([10, 10000], [1., 1.]),
transmission_only=True)
world = World()
torus = Torus(1.0, 0.5)
cylinder = Cylinder(1.0, 1.0, transform=translate(0, 0, -0.5))
union = Union(torus, cylinder, material=glass, parent=world)
ray = LoggingRay(origin=Point3D(2., 0, 0), direction=Vector3D(-1, 0, 0))
ray.trace(world)
for intersection in ray.log:
print(intersection.hit_point, intersection.exiting)
print()
is
Point3D(1.5, 0.0, 0.0) False
Point3D(1.4999997776219791, 0.0, 0.0) False
Point3D(-1.0, 0.0, 0.0) True
Point3D(-1.5, 0.0, 0.0) True
The intersection at Point3D(-1.0, 0.0, 0.0) is an extra one because the ray is not exciting the primitive at (-1, 0, 0).
Hello,
I would like to create a PR about a new Torus primitive. Additionally, I implemented required functionalities to solve quartic, cubic equations, etc.
If you agree to this PR, then I will add or modify the documentations written about primitives' sections. The example rendering of a torus primitive is below, the script of which is
demos/primitives/simple_torus.py
.I would appreciate it if you would review my codes and comment this PR.