6
$\begingroup$

In my application, I am attempting to connect 2 points in 3d space with a cylinder via a function taking in 2 vectors. I understand that I need the angle to apply to the cylinder. As I understand, I can calculate this angle with the dot product of both vectors. How can I know how to apply the angle given this function:

func SCNMatrix4MakeRotation(angle: Float, x: Float, y: Float, z: Float) -> SCNMatrix4

where:

angle: The amount of rotation, in radians, measured counterclockwise around the rotation axis.
x: The x-component of the rotation axis.
y: The y-component of the rotation axis.
z: The z-component of the rotation axis.

How should I apply the correct angle here? Parameters x, y, and z take in a number between 0 and 1. With respect to which plane does the rotation occur?

$\endgroup$
16
$\begingroup$

[Not sure if this information is completely what you're looking for, but it certainly is relevant. Please give a more specific problem statement or a simple worked example and I'll be happy to expand/refine my answer.]

The angle between vectors $\vec{x}$ and $\vec{y}$ is defined using the dot product like so: $$ \cos(\theta) = \frac{\vec{x}\cdot \vec{y}}{\|\vec{x}\| \ \|\vec{y}\|}$$ where the expression $\|\vec{a}\| = \sqrt{a_1^2 + a_2^2 + a_3^2}$ is the magnitude/norm of a vector. The magnitude of a vector in 3D space is just the square root of the sum of the squares of the $i,j,k$ components of that vector.

By using the inverse cosine function, you can determine the angle between the vectors. You'll have to pay attention to the sign of the dot product to determine if the resulting angle is acute (positive dot product), perpendicular (zero dot product), or obtuse (negative dot product).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.