简体   繁体   中英

Rotation of a Vector around a point in 3D space with specific x,y&z angles [JAVA]

for my playermodel i have several bodyparts at specific positions like this: the right arm at [-2, 2 ,0] and the second part of the arm is located at [-2, 6, 0] Now i want to rotate the first part of the arm and want the second part of the arm at the end of the first part. I have already got something working for it with mycode, but the point is not always translated to the correct position.

This is what i have so far:

public static Vector3d rotateVectorAroundOrigin(Vector3d angle, Vector3f origin, Vector3f point) {
    double radius = Math.sqrt(((point.x - origin.x) * (point.x - origin.x))
            + ((point.y - origin.y) * (point.y - origin.y)) + ((point.z - origin.z) * (point.z - origin.z)));

    double newX = origin.x + (radius * (Math.sin(angle.z) * Math.sin(angle.y)));
    double newY = origin.y + (radius * Math.cos(angle.x));
    double newZ = origin.z + (radius * Math.sin(angle.y) * Math.cos(angle.y) * Math.sin(angle.z));

    return new Vector3d(newX, newY, newZ);
}

Hope somebody can help me

I'm not exactly sure the math you are using in your equations, so I just figured it out the way I was taught for converting from a vector magnitude and angle into a point. The equation you are looking for for the final point is: P_f = new double {4cos(angle) + x_0, 4sin(angle) + y_0, z_0}

Please note that this only works rotating in one direction . In other words, it will only work for rotation in the xy-plane, not a rotation from the z-plane. This is because for a rotation in multiple planes, you will need an angle in each plane .

Reference

第一

Equation for second point

第二

Example of angles in 3-D

第三

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM