Rotates the vector around a given arbitrary axis in 3 dimensional space. Rotation will follow the general Right-Hand-Rule, which means rotation will be counterclockwise when the axis is pointing towards the observer. Note that the vector length will change accordingly to the axis vector len
(@NotNull Vector axis, double angle)
| 527 | * null |
| 528 | */ |
| 529 | @NotNull |
| 530 | public Vector rotateAroundNonUnitAxis(@NotNull Vector axis, double angle) throws IllegalArgumentException { |
| 531 | Preconditions.checkArgument(axis != null, "The provided axis vector was null"); |
| 532 | |
| 533 | double x = getX(), y = getY(), z = getZ(); |
| 534 | double x2 = axis.getX(), y2 = axis.getY(), z2 = axis.getZ(); |
| 535 | |
| 536 | double cosTheta = Math.cos(angle); |
| 537 | double sinTheta = Math.sin(angle); |
| 538 | double dotProduct = this.dot(axis); |
| 539 | |
| 540 | double xPrime = x2 * dotProduct * (1d - cosTheta) |
| 541 | + x * cosTheta |
| 542 | + (-z2 * y + y2 * z) * sinTheta; |
| 543 | double yPrime = y2 * dotProduct * (1d - cosTheta) |
| 544 | + y * cosTheta |
| 545 | + (z2 * x - x2 * z) * sinTheta; |
| 546 | double zPrime = z2 * dotProduct * (1d - cosTheta) |
| 547 | + z * cosTheta |
| 548 | + (-y2 * x + x2 * y) * sinTheta; |
| 549 | |
| 550 | return setX(xPrime).setY(yPrime).setZ(zPrime); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Gets the X component. |