Skip to content

Commit 5d902d0

Browse files
cem-keskincopybara-github
authored andcommitted
Exposes eps argument for tfg.math.cartesian_to_spherical_coordinates.
PiperOrigin-RevId: 311384397
1 parent af7f2f9 commit 5d902d0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tensorflow_graphics/math/math_helpers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from tensorflow_graphics.util import shape
2727

2828

29-
def cartesian_to_spherical_coordinates(point_cartesian, name=None):
29+
def cartesian_to_spherical_coordinates(point_cartesian, eps=None, name=None):
3030
"""Function to transform Cartesian coordinates to spherical coordinates.
3131
3232
This function assumes a right handed coordinate system with `z` pointing up.
@@ -39,6 +39,8 @@ def cartesian_to_spherical_coordinates(point_cartesian, name=None):
3939
Args:
4040
point_cartesian: A tensor of shape `[A1, ..., An, 3]`. In the last
4141
dimension, the data follows the `x`, `y`, `z` order.
42+
eps: A small `float`, to be added to the denominator. If left as `None`,
43+
its value is automatically selected using `point_cartesian.dtype`.
4244
name: A name for this op. Defaults to `cartesian_to_spherical_coordinates`.
4345
4446
Returns:
@@ -57,7 +59,7 @@ def cartesian_to_spherical_coordinates(point_cartesian, name=None):
5759

5860
x, y, z = tf.unstack(point_cartesian, axis=-1)
5961
radius = tf.norm(tensor=point_cartesian, axis=-1)
60-
theta = tf.acos(safe_ops.safe_unsigned_div(z, radius))
62+
theta = tf.acos(safe_ops.safe_unsigned_div(z, radius, eps))
6163
phi = tf.atan2(y, x)
6264
return tf.stack((radius, theta, phi), axis=-1)
6365

0 commit comments

Comments
 (0)