geoclide.quadrics module#
- class geoclide.quadrics.Disk(radius, inner_radius=0.0, phi_max=360.0, z_height=0.0, oTw=None, wTo=None)#
Bases:
Shape
Creation of the class Disk
- Parameters:
- radiusfloat
The disk radius
- inner_radiusfloat, optional
The inner radius (case of annulus)
- phi_maxfloat, optional
The maximum phi value in degrees of the disk/annulus, where phi is between 0 and 360°
- z_heightfloat, optional
the disk height along the z axis
- oTwTransform, optional
From object to world space or the transformation applied to the spheroid
- wToTransform, optional
From world to object space or the in inverse transformation applied to the spheroid
Methods
area
()compute the disk / annulus area
intersect
(r[, ds_output])Test if a ray/set of rays intersects the disk
Test if a ray/set of rays intersects the disk
Test if a ray/set of rays intersects the disk
plot
(**kwargs)Plot the disk
to_trianglemesh
([reso])Convert the disk to a triangle mesh
Notes
Even if z_height is given, the origin for rotation transformation do not change. For exemple: z_height=5 then we apply a rotation of 90 degrees around the y axis, the disk we be rotated from (0.,0.,0.), meaning the disk we be moved from position (0.,0.,5.) to (5.,0.,0.).
- area()#
compute the disk / annulus area
Warning
the scale transformation is not considered for the area calculation!
- intersect(r, ds_output=True)#
Test if a ray/set of rays intersects the disk
- Parameters:
- rRay
The ray(s) to use for the intersection test(s)
- ds_outputBool, optional
If True the output is a dataset, else -> a tuple with intersection information variables
- Returns:
- outxr.Dataset | tuple
Look-up table with the intersection information if ds_output is True, else returns a tuple. The tuple is ready to be an input for the function geoclide.shapes.get_intersect_dataset
Examples
>>> import geoclide as gc >>> r1 = gc.Ray(gc.Point(1.2,0.,10.), gc.Vector(0.,0.,-1.)) >>> annulus = gc.Disk(radius=1.5, inner_radius=0.8) >>> annulus.intersect(r1) # hit point is between the inner radius and radius <xarray.Dataset> Size: 209B Dimensions: (xyz: 3) Coordinates: * xyz (xyz) int64 24B 0 1 2 Data variables: o (xyz) float64 24B 1.2 0.0 10.0 d (xyz) float64 24B 0.0 0.0 -1.0 mint int64 8B 0 maxt float64 8B inf is_intersection bool 1B True thit float64 8B 10.0 u float64 8B 0.0 v float64 8B 0.4286 phit (xyz) float64 24B 1.2 0.0 0.0 nhit (xyz) float64 24B 0.0 0.0 1.0 dpdu (xyz) float64 24B 0.0 7.54 0.0 dpdv (xyz) float64 24B -0.7 -0.0 -0.0
- is_intersection(r)#
Test if a ray/set of rays intersects the disk
- Parameters:
- rRay
The ray(s) to use for the intersection test
- Returns:
- is_intersectionbool | 1-D ndarray
If there is an intersection -> True, else False
Examples
>>> import geoclide as gc >>> r1 = gc.Ray(gc.Point(1.2,0.,10.), gc.Vector(0.,0.,-1.)) >>> r2 = gc.Ray(gc.Point(0.2,0.,10.), gc.Vector(0.,0.,-1.)) >>> r3 = gc.Ray(gc.Point(1.6,0.,10.), gc.Vector(0.,0.,-1.)) >>> annulus = gc.Disk(radius=1.5, inner_radius=0.8) >>> annulus.is_intersection(r1) # hit point is between the inner radius and radius True >>> annulus.is_intersection(r2) # the ray passes through the annulus hole, no intersection False >>> annulus.is_intersection(r3) # the ray passes outside, no intersection False
- is_intersection_t(r)#
Test if a ray/set of rays intersects the disk
- Parameters:
- rRay
The ray(s) to use for the intersection test
- Returns:
- thitfloat | 1-D ndarray
The t ray variable(s) for its first intersection at the shape surface
- is_intersectionbool | 1-D ndarray
If there is an intersection -> True, else False
Examples
>>> import geoclide as gc >>> r1 = gc.Ray(gc.Point(1.2,0.,10.), gc.Vector(0.,0.,-1.)) >>> r2 = gc.Ray(gc.Point(0.2,0.,10.), gc.Vector(0.,0.,-1.)) >>> r3 = gc.Ray(gc.Point(1.6,0.,10.), gc.Vector(0.,0.,-1.)) >>> annulus = gc.Disk(radius=1.5, inner_radius=0.8) >>> annulus.is_intersection_t(r1) # hit point is between the inner radius and radius (10.0, True) >>> annulus.is_intersection_t(r2) # the ray passes through the annulus hole, no intersection (None, False) >>> annulus.is_intersection_t(r3) # the ray passes outside, no intersection (None, False)
- plot(**kwargs)#
Plot the disk
The disk is first converted to a triangle mesh then the TriangleMesh plot method is used
- Parameters:
- **kwargs
The keyword arguments are passed on to the TriangleMesh plot method
- to_trianglemesh(reso=None)#
Convert the disk to a triangle mesh
- Parameters:
- resoint, optional
The number of lines around the polar phi angle, minimum accepted value is 3
- Returns:
- meshTriangleMesh
The disk converted to a triangle mesh
- class geoclide.quadrics.Sphere(radius, z_min=None, z_max=None, phi_max=360.0, oTw=None, wTo=None)#
Bases:
Shape
Creation of the class Sphere
without transformation the sphere is centered at the origin
z0, z1 and phi_max are needed parameters for the creation of any partial sphere
- Parameters:
- radiusfloat
The radius of the sphere
- z_minfloat, optional
The minimum z value of the sphere where z0 is between [-radius, 0]
- z_maxfloat, optional
The maximum z value of the sphere where z1 is between [0, radius]
- phi_maxfloat, optional
The maximum phi value in degrees of the sphere, where phi is between 0 and 360°
- oTwTransform, optional
From object to world space or the transformation applied to the sphere
- wToTransform, optional
From world to object space or the in inverse transformation applied to the sphere
Methods
area
()compute the sphere / partial sphere area
intersect
(r[, ds_output])Test if a ray/set of rays intersects the sphere/partial sphere
Test if a ray/set of rays intersects the sphere / partial sphere
Test if a ray/set of rays intersects the sphere/partial sphere
plot
(**kwargs)Plot the sphere
to_trianglemesh
([reso_theta, reso_phi])Convert the sphere to a triangle mesh
- area()#
compute the sphere / partial sphere area
Warning
the scale transformation is not considered for the area calculation!
- intersect(r, ds_output=True)#
Test if a ray/set of rays intersects the sphere/partial sphere
- Parameters:
- rRay
The ray(s) to use for the intersection test(s)
- ds_outputBool, optional
If True the output is a dataset, else -> a tuple with intersection information variables
- Returns:
- outxr.Dataset | tuple
Look-up table with the intersection information if ds_output is True, else returns a tuple. The tuple is ready to be an input for the function geoclide.shapes.get_intersect_dataset
Examples
>>> import geoclide as gc >>> sph1 = gc.Sphere(radius=1.) # sphere of radius 1 >>> sph2 = gc.Sphere(radius=1., z_max=0.5) # partial sphere where portion above z=0.5 is removed >>> r = gc.Ray(o=gc.Point(-2., 0., 0.8), d=gc.Vector(1.,0.,0.)) >>> sph1.intersect(r) <xarray.Dataset> Size: 209B Dimensions: (xyz: 3) Coordinates: * xyz (xyz) int64 24B 0 1 2 Data variables: o (xyz) float64 24B -2.0 0.0 0.8 d (xyz) float64 24B 1.0 0.0 0.0 mint int64 8B 0 maxt float64 8B inf is_intersection bool 1B True thit float64 8B 1.4 u float64 8B 0.5 v float64 8B 0.7952 phit (xyz) float64 24B -0.6 0.0 0.8 nhit (xyz) float64 24B -0.6 0.0 0.8 dpdu (xyz) float64 24B 0.0 -3.77 0.0 dpdv (xyz) float64 24B 2.513 0.0 1.885 >>> ds = sph1.intersect(r) >>> ds['phit'].values # the intersection point array([-0.6, 0. , 0.8]) >>> ds['nhit'].values # The surface normal at the intersection point array([-0.6, 0. , 0.8]) >>> sph2.intersect(r) # here no intersection since the sphere part above z=0.5 is removed <xarray.Dataset> Size: 209B Dimensions: (xyz: 3) Coordinates: * xyz (xyz) int64 24B 0 1 2 Data variables: o (xyz) float64 24B -2.0 0.0 0.8 d (xyz) float64 24B 1.0 0.0 0.0 mint int64 8B 0 maxt float64 8B inf is_intersection bool 1B False thit object 8B None u object 8B None v object 8B None phit (xyz) float64 24B nan nan nan nhit (xyz) float64 24B nan nan nan dpdu (xyz) float64 24B nan nan nan dpdv (xyz) float64 24B nan nan nan
- is_intersection(r)#
Test if a ray/set of rays intersects the sphere / partial sphere
- Parameters:
- rRay
The ray(s) to use for the intersection test
- Returns:
- outbool | 1-D ndarray
If there is an intersection -> True, else False
Examples
>>> import geoclide as gc >>> sph1 = gc.Sphere(radius=1.) # sphere of radius 1 >>> sph2 = gc.Sphere(radius=1., z_max=0.5) # partial sphere where portion above z=0.5 is removed >>> r = gc.Ray(o=gc.Point(-2., 0., 0.8), d=gc.Vector(1.,0.,0.)) >>> sph1.is_intersection(r) True >>> sph2.is_intersection(r) # here no intersection since the sphere part above z=0.5 is removed False
- is_intersection_t(r)#
Test if a ray/set of rays intersects the sphere/partial sphere
- Parameters:
- rRay
The ray(s) to use for the intersection test
- Returns:
- thitfloat | 1-D ndarray
The t ray variable(s) for its first intersection at the shape surface
- is_intersectionbool | 1-D ndarray
If there is an intersection -> True, else False
Examples
>>> import geoclide as gc >>> sph1 = gc.Sphere(radius=1.) # sphere of radius 1 >>> sph2 = gc.Sphere(radius=1., z_max=0.5) # partial sphere where portion above z=0.5 is removed >>> r = gc.Ray(o=gc.Point(-2., 0., 0.8), d=gc.Vector(1.,0.,0.)) >>> sph1.is_intersection_t(r) (1.4000000000000004, True) >>> sph2.is_intersection(r) # here no intersection since the sphere part above z=0.5 is removed False
- plot(**kwargs)#
Plot the sphere
The sphere is first converted to a triangle mesh then the TriangleMesh plot method is used
- Parameters:
- **kwargs
The keyword arguments are passed on to the TriangleMesh plot method
- to_trianglemesh(reso_theta=None, reso_phi=None)#
Convert the sphere to a triangle mesh
- Parameters:
- reso_thetaint, optional
The number of lines around the polar theta angle, minimum accepted value is 3
- reso_phiint, optional
The number of lines around the azimuth phi angle, minimum accepted value is 3
- Returns:
- meshTriangleMesh
The sphere converted to a triangle mesh
- class geoclide.quadrics.Spheroid(radius_xy, radius_z, oTw=None, wTo=None)#
Bases:
Shape
Creation of the class Spheroid
without transformation the spheroid is centered at the origin
spheroid equation: x/(alpha**2) + y/(alpha**2) + z/(gamma**2) = 1, where alpha = radius_xy and gamma = radius_z
prolate -> radius_z > radius_xy
oblate -> radius_z < radius_xy
- Parameters:
- radius_xyfloat
The equatorial radius of the spheroid
- radius_zfloat
The pole radius of the spheroid (distance from center to pole along z axis)
- oTwTransform, optional
From object to world space or the transformation applied to the spheroid
- wToTransform, optional
From world to object space or the in inverse transformation applied to the spheroid
Methods
area
()compute the spheroid area
intersect
(r[, ds_output])Test if a ray/set of rays intersects the spheroid
Test if a ray/set of rays intersects the spheroid
Test if a ray/set of rays intersects the spheroid
plot
(**kwargs)Plot the spheroid
to_trianglemesh
([reso_theta, reso_phi])Convert the spheroid to a triangle mesh
- area()#
compute the spheroid area
Warning
the scale transformation is not considered for the area calculation!
- intersect(r, ds_output=True)#
Test if a ray/set of rays intersects the spheroid
- Parameters:
- rRay
The ray(s) to use for the intersection test(s)
- ds_outputBool, optional
If True the output is a dataset, else -> a tuple with intersection information variables
- Returns:
- outxr.Dataset | tuple
Look-up table with the intersection information if ds_output is True, else returns a tuple. The tuple is ready to be an input for the function geoclide.shapes.get_intersect_dataset
Examples
>>> import geoclide as gc >>> oblate = gc.Spheroid(radius_xy=3., radius_z=1.5) >>> prolate = gc.Spheroid(radius_xy=1.5, radius_z=3.) >>> r1 = gc.Ray(o=gc.Point(2.5, 0., 10.), d=(gc.Vector(0., 0., -1.))) >>> r2 = gc.Ray(o=gc.Point(10., 0., 2.5), d=(gc.Vector(-1., 0., 0.))) >>> oblate.intersect(r1) <xarray.Dataset> Size: 209B Dimensions: (xyz: 3) Coordinates: * xyz (xyz) int64 24B 0 1 2 Data variables: o (xyz) float64 24B 2.5 0.0 10.0 d (xyz) float64 24B 0.0 0.0 -1.0 mint int64 8B 0 maxt float64 8B inf is_intersection bool 1B True thit float64 8B 9.171 u float64 8B 0.0 v float64 8B 0.6864 phit (xyz) float64 24B 2.5 0.0 0.8292 nhit (xyz) float64 24B 0.6019 -0.0 0.7985 dpdu (xyz) float64 24B 0.0 15.71 0.0 dpdv (xyz) float64 24B -5.21 0.0 3.927 >>> prolate.intersect(r2) <xarray.Dataset> Size: 209B Dimensions: (xyz: 3) Coordinates: * xyz (xyz) int64 24B 0 1 2 Data variables: o (xyz) float64 24B 10.0 0.0 2.5 d (xyz) float64 24B -1.0 0.0 0.0 mint int64 8B 0 maxt float64 8B inf is_intersection bool 1B True thit float64 8B 9.171 u float64 8B 0.0 v float64 8B 0.8136 phit (xyz) float64 24B 0.8292 0.0 2.5 nhit (xyz) float64 24B 0.7985 -0.0 0.6019 dpdu (xyz) float64 24B 0.0 5.21 0.0 dpdv (xyz) float64 24B -3.927 0.0 5.21
- is_intersection(r)#
Test if a ray/set of rays intersects the spheroid
- Parameters:
- rRay
The ray(s) to use for the intersection test
- Returns:
- outbool | 1-D ndarray
If there is an intersection -> True, else False
Examples
>>> import geoclide as gc >>> oblate = gc.Spheroid(radius_xy=3., radius_z=1.5) >>> prolate = gc.Spheroid(radius_xy=1.5, radius_z=3.) >>> r1 = gc.Ray(o=gc.Point(2.5, 0., 10.), d=(gc.Vector(0., 0., -1.))) >>> r2 = gc.Ray(o=gc.Point(10., 0., 2.5), d=(gc.Vector(-1., 0., 0.))) >>> oblate.is_intersection(r1) True >>> oblate.is_intersection(r2) False >>> prolate.is_intersection(r1) False >>> prolate.is_intersection(r2) True
- is_intersection_t(r)#
Test if a ray/set of rays intersects the spheroid
- Parameters:
- rRay
The ray(s) to use for the intersection test
- Returns:
- thitfloat | 1-D ndarray
The t ray variable(s) for its first intersection at the shape surface
- is_intersectionbool | 1-D ndarray
If there is an intersection -> True, else False
Examples
>>> import geoclide as gc >>> oblate = gc.Spheroid(radius_xy=3., radius_z=1.5) >>> prolate = gc.Spheroid(radius_xy=1.5, radius_z=3.) >>> r1 = gc.Ray(o=gc.Point(2.5, 0., 10.), d=(gc.Vector(0., 0., -1.))) >>> r2 = gc.Ray(o=gc.Point(10., 0., 2.5), d=(gc.Vector(-1., 0., 0.))) >>> oblate.is_intersection_t(r1) (9.170843802411135, True) >>> oblate.is_intersection_t(r2) (None, False) >>> prolate.is_intersection_t(r1) (None, False) >>> prolate.is_intersection_t(r2) (9.170843802411135, True)
- plot(**kwargs)#
Plot the spheroid
The spheroid is first converted to a triangle mesh then the TriangleMesh plot method is used
- Parameters:
- **kwargs
The keyword arguments are passed on to the TriangleMesh plot method
- to_trianglemesh(reso_theta=None, reso_phi=None)#
Convert the spheroid to a triangle mesh
- Parameters:
- reso_thetaint, optional
The number of lines around the polar theta angle, minimum accepted value is 3
- reso_phiint, optional
The number of lines around the azimuth phi angle, minimum accepted value is 3
- Returns:
- meshTriangleMesh
The spheroid converted to a triangle mesh