# I want to Rotate to a certain angle, not how much increment

I have a bone’s head and end location data:

head: {x: 0.9733360409736633, y: 0.9454540610313416, z: -0.7999792695045471}
end: {x: 0.7157449126243591, y: 0.39291810989379883, z: -1.254652738571167}

how can I rotate the bone to match the head and end?

or by rotate to a certain angle, not by how much increment?

pilot.rotation = new BABYLON.Vector3(alpha, beta, gamma);
or rotate(BABYLON.Axis.Y, Math.PI / 2, BABYLON.Space.WORLD);
is rotate by increment

Hello, I am not sure to understand what you are trying to achieve, can you provide a playground highlighting your current trials as it might help to get the exact use case.

if I receive a command: move the left up arm bone of skeleton to match this positon:
bone head: {x: 0.9733360409736633, y: 0.9454540610313416, z: -0.7999792695045471}
bone end: {x: 0.7157449126243591, y: 0.39291810989379883, z: -1.254652738571167}

how can I achieve this command？

It depends on the number of joints and where they are located. If either head or end is the pivot point and located in the correct position, then calculate the angle between the current vector and the desired vector using rotation axis orthogonal to the rotation and through the pivot point. That’s the angle of rotation around the pivot needed to get to the final vector. For this to work, the axis of rotation must align with the joint rotation.

You’d need to provide much more information, ideally a playground, for anyone to supply additional help.

yes, the key is how to “calculate the angle between the current vector and the desired vector”.

can you help write a example for about “calculate the angle between the current vector and the desired vector using rotation axis orthogonal to the rotation and through the pivot point.”

Have a look at BABYLON.Vector3.

You can calculate the angle between two vectors using the dot product and the magnitudes of the vectors. The dot product of two vectors can be found by multiplying their corresponding components and then summing the results. The formula for finding the angle between two vectors v1 and v2 is:

Copy

``````cos(θ) = (v1 • v2) / (||v1|| * ||v2||)
``````

Where:

• θ is the angle between the two vectors.

• v1 • v2 is the dot product of the two vectors.

• ||v1|| and ||v2|| are the magnitudes (lengths) of the respective vectors.

Once you have the value of cos(θ), you can calculate the angle θ by taking the inverse cosine (arccos) of the value:

Copy

``````θ = arccos(cos(θ))
``````

To calculate this in Python, you can use the NumPy library to perform vector operations. Here’s an example of how to calculate the angle between two vectors v1 and v2:

PythonCopy

``````import numpy as np

# Create two example vectors
v1 = np.array([2, 3])
v2 = np.array([3, 1])

# Calculate the dot product of the vectors
dot_product = np.dot(v1, v2)

# Calculate the magnitudes of the vectors
magnitude_v1 = np.linalg.norm(v1)
magnitude_v2 = np.linalg.norm(v2)

# Calculate the angle using the arccos function
angle = np.arccos(dot_product / (magnitude_v1 * magnitude_v2))

print("Angle between the vectors (in radians):", angle)
``````

This script first calculates the dot product of the two vectors using the np.dot() function. It then calculates the magnitudes of the vectors using the np.linalg.norm() function. Finally, it computes the angle between the vectors using the np.arccos() function. The result is printed in radians, but you can convert it to degrees if needed by multiplying the angle by 180 / np.pi.

1 Like

and here is a fundamental description of how to rotate vectors

I hope this helps!

1 Like

You can also check out in action in this old example of mine. Here it is calculating angle against UP vector, but you can adjust it to work with any two vectors.

2 Likes

You would need smthg like this Babylon.js docs

thanks a lot.
But how can I get the current vector of a bone ?