Tariq Islam
Tariq Islam

Reputation: 23

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))

Upvotes: 0

Views: 133

Answers (2)

William Miller
William Miller

Reputation: 10328

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.

Upvotes: 0

Timo
Timo

Reputation: 43

The angle should be more than 90°. Compare (0, 0, 1) with (-51.85, 0,0), that has an angle of exactly 90°. If we now have (-51.85, 0, -0.93) comparing the z value, then this -9.93 points in the opposite direction of the 1 in (0, 0, 1) which increases the angle from 90° to something bigger. Similar with the y value. Imagining both vectors in 3D helps.

Upvotes: 1

Related Questions