Search code examples
pythonmathvectorgeometryphysics

Unexpected angle value


Image portraying my problem

I have a vector A with coordinates (-51.85,-2.38,-0.93). The normal vector at point A(lets call it Na) is (0,0,1). I want to calculate the angle between the position vector A and the normal vector Na. Intuitively, looking at the coordinates of A and the straight upward facing normal, the angle should be less than 90. However, i am getting a value more than 90. Can you explain, why is it so, where am i doing it wrong. Please have a look at the attached code.

import numpy as np
import math

point_vector = np.array([-51.85,-2.38,-0.93])
normalized_point_vector = point_vector / np.linalg.norm(point_vector)
normal = np.array([0,0,1])
# Normalize the normal vector
normalized_normal = normal / np.linalg.norm(normal)

# Calculate the angle of incidence using the dot product
dot_product = np.dot(normalized_point_vector, normalized_normal)
angle = np.arccos(dot_product)

if angle>math.pi / 2:
   print("angle is:",angle*(180/math.pi))

Solution

  • The angle between two vectors is taken with common origin, i.e.

    enter image description here

    Not

    enter image description here

    Your intuition is correct about the angle you drew, but that is not the angle you are calculating in your code. The correct angle between (0, 0, 1) and (-51.85, -2.38, -0.93) is 91.0265 degrees, exactly what your code gives.