raysect / source

The main source repository for the Raysect project.
http://www.raysect.org
BSD 3-Clause "New" or "Revised" License
88 stars 23 forks source link

Random direction and origin for an observer #258

Closed Mateasek closed 5 years ago

Mateasek commented 5 years ago

It would be nice to have a function which would generate random direction (Vector3D) and origin (Point3D) of a ray from an observer. It could work nicely together with LoggingRay class.

It could be close to _generate_rays function of FIbreOptic class: https://github.com/raysect/source/blob/690b7440caa7087b855e2726fb1f63e02c22d668/raysect/optical/observer/nonimaging/fibreoptic.pyx#L138-L161

something like:

cpdef tuple generate_origins_directions(self, int ray_count):
        cdef:
            list vectors, origins

        origins = self._point_sampler.samples(ray_count)
        vectors = self._vector_sampler.samples(ray_count)

        return origins, vectors
mattngc commented 5 years ago

Hi Matej,

Are you sure this functionality doesn't exist already? The _generate_rays() function in all the classes is based on a set of utility functions in the core math classes. Maybe they aren't documented well enough with examples.

The respective utility functions we use are located here: https://github.com/raysect/source/blob/master/raysect/core/math/sampler/surface3d.pyx https://github.com/raysect/source/blob/master/raysect/core/math/sampler/solidangle.pyx

And there is some documentation on how to use them in the API docs: https://raysect.github.io/documentation/api_reference/core/random.html#raysect.core.math.sampler.surface3d.SurfaceSampler3D https://raysect.github.io/documentation/api_reference/core/random.html#raysect.core.math.sampler.solidangle.SolidAngleSampler

You should be able to use them by initialising the class with the desired properties and then simply calling the class with the number of samples you want.

Do you still think some functionality is missing? Maybe I just need to document it better?

Mateasek commented 5 years ago

Hi Matt,

thanks for the answer, that is actually all I needed. I was trying to get a random vector and origin through FIbreOptic object, which was impossible. This is exactly what I need. The documentation is sufficient, it is my searching and python skills which need to be improved :-D

I think we can close this.