# tfg.rendering.camera.perspective.ray

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/rendering/camera/perspective.py#L391-L454) |

Computes the 3d ray for a 2d point (the z component of the ray is 1).

    tfg.rendering.camera.perspective.ray(
        point_2d: type_alias.TensorLike,
        focal: type_alias.TensorLike,
        principal_point: type_alias.TensorLike,
        name: str = 'perspective_ray'
    ) -> tf.Tensor

Computes the 3d ray \\((r_x, r_y, 1)\\) from the camera center to a 2d point
\\((x', y')\\) on the image plane with

\\\[
\\begin{matrix}
r_x = \\frac{(x' - c_x)}{f_x}, \& r_y = \\frac{(y' - c_y)}{f_y}, \& z = 1,
\\end{matrix}
\\\]

where \\((f_x, f_y)\\) is the focal length and \\((c_x, c_y)\\) the principal
point. The camera optical center is assumed to be at \\((0, 0, 0)\\).

<br />

<br />

<br />

| ## Note ||
|---|---|
| In the following, A1 to An are optional batch dimensions that must be broadcast compatible. ||

<br />

<br />

<br />

<br />

| ## Args ||
|---|---|
| `point_2d` | A tensor of shape `[A1, ..., An, 2]`, where the last dimension represents a 2d point. |
| `focal` | A tensor of shape `[A1, ..., An, 2]`, where the last dimension represents a camera focal length. |
| `principal_point` | A tensor of shape `[A1, ..., An, 2]`, where the last dimension represents a camera principal point. |
| `name` | A name for this op that defaults to "perspective_ray". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor of shape `[A1, ..., An, 3]`, where the last dimension represents a 3d ray. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the shape of `point_2d`, `focal`, or `principal_point` is not supported. |

<br />