TensorTonic
Problems
Angle Between 3D Vectors
3D Geometry
Medium

Compute the angle in radians between two 3D vectors. First obtain their cosine:

c=v⋅w∥v∥2∥w∥2c=\frac{\mathbf{v}\cdot\mathbf{w}}{\lVert\mathbf{v}\rVert_2\lVert\mathbf{w}\rVert_2}c=∥v∥2​∥w∥2​v⋅w​

Then recover the angle:

θ=arccos⁡(c)\theta=\arccos(c)θ=arccos(c)

Clamp ccc to [−1,1][-1,1][−1,1] before applying arccos to protect against floating-point error. If either vector has zero norm, the angle is undefined, so return np.nan. Otherwise return a Python float in [0,π][0,\pi][0,π].

Loading visualization...

Examples

Input: v = [1, 0, 0], w = [0, 1, 0]

Output: 1.570796

Explanation: Orthogonal vectors have cosine zero and an angle of pi divided by two.

Input: v = [1, 2, 3], w = [2, 4, 6]

Output: 0

Hint 1

Use np.dot(v, w) for the numerator and squared sums for both norms.

Hint 2

Pass np.clip(cosine, -1.0, 1.0) to np.arccos.

Requirements

  • Compute both Euclidean norms and the dot product
  • Return np.nan when either norm is zero
  • Clamp the cosine before applying np.arccos
  • Return a Python float

Constraints

  • Both inputs contain exactly three numeric values
  • Use NumPy only
Try Similar Problems
Apply 4×4 Homogeneous TransformMediumRotate 3D Point Around Z-AxisMediumNormalize 3D VectorsEasyCompute 3D Vector NormEasyImplement Dot ProductEasy
Scratchpad

Accepts: array

Accepts: array

You must run your code first.
Angle Between 3D Vectors

Angle Between 3D Vectors

3D Geometry
Medium

Compute the angle in radians between two 3D vectors. First obtain their cosine:

c=v⋅w∥v∥2∥w∥2c=\frac{\mathbf{v}\cdot\mathbf{w}}{\lVert\mathbf{v}\rVert_2\lVert\mathbf{w}\rVert_2}c=∥v∥2​∥w∥2​v⋅w​

Then recover the angle:

θ=arccos⁡(c)\theta=\arccos(c)θ=arccos(c)

Clamp ccc to [−1,1][-1,1][−1,1] before applying arccos to protect against floating-point error. If either vector has zero norm, the angle is undefined, so return np.nan. Otherwise return a Python float in [0,π][0,\pi][0,π].

Loading visualization...

Examples

Input: v = [1, 0, 0], w = [0, 1, 0]

Output: 1.570796

Explanation: Orthogonal vectors have cosine zero and an angle of pi divided by two.

Input: v = [1, 2, 3], w = [2, 4, 6]

Output: 0

Hint 1

Use np.dot(v, w) for the numerator and squared sums for both norms.

Hint 2

Pass np.clip(cosine, -1.0, 1.0) to np.arccos.

Requirements

  • Compute both Euclidean norms and the dot product
  • Return np.nan when either norm is zero
  • Clamp the cosine before applying np.arccos
  • Return a Python float

Constraints

  • Both inputs contain exactly three numeric values
  • Use NumPy only
Try Similar Problems
Apply 4×4 Homogeneous TransformMediumRotate 3D Point Around Z-AxisMediumNormalize 3D VectorsEasyCompute 3D Vector NormEasyImplement Dot ProductEasy
Scratchpad

Accepts: array

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1