I want to calculate the angle between the two vectors by considering the direction of the vector with numpy.

Asked 2 years ago, Updated 2 years ago, 48 views

First, do the following:
Write a function that calculates the angle between the vector x and the vector y.

import numpy as np

default(x,y):

    dot_xy=np.dot(x,y)
    norm_x = np.linalg.norm(x)
    norm_y = np.linalg.norm(y)
    cos=dot_xy/(normal_x*normal_y)
    rad=np.arccos(cos)
    theta=rad*180/np.pi

    return theta

Then use this function to
Calculate the angle of vector x and vector y below.

x=np.array([1,0,1])
y = np.array ([1,1,1])
print angle(x,y)

This result, of course, is 45.0.

Now calculate the angle between the vector x above and the vector z below.

z=np.array([1,-1,1])
print angle(x,z)

Of course, 45.0 will be output at the same angle as above.

But here,
When calculated by x and y, use
positive direction. I would like to print 315.0 instead of 45.0 for the angle of x and z.

What should I do with numpy?
Can you calculate the angle by fixing the direction of the vector?

Thank you for your cooperation.

python numpy

2022-09-30 17:44

1 Answers

As you commented, it was a problem that could be solved by determining the code.
Sorry for the trouble.Thank you.


2022-09-30 17:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.