/** * Returns a new transform representing a rotation around an * axis around the origin. The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. * The rotation is around the block center, not the corner. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @return The new rotation transform */ public static DiscreteTransform3 fromRotation(int quarterTurns, Axis axis) { return new DiscreteTransform3(Matrix4d.createRotation(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d()))); }
/** * Adds a rotation to this transform, around an axis, * around the origin and returns it as a new transform. * The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. * The rotation is around the block center, not the corner. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @return The rotated transform as a copy */ public DiscreteTransform3 withRotation(int quarterTurns, Axis axis) { return new DiscreteTransform3(this.matrix.rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d()))); }
/** * Returns a new transform representing a rotation around an axis, * around a given point. The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. The block corner * flag change the point to be the block corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The new rotation transform */ public static DiscreteTransform3 fromRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3(Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis .toVector3d())).translate(pointDouble)); }
/** * Adds a a rotation to this transform, around an axis, * around a given point, and returns it as a new transform. * The rotation is given is quarter turns. The actual rotation * is {@code quarterTurns * 90}. The block corner flag changes * the point to be the block upper corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The rotated transform as a copy */ public DiscreteTransform3 withRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3( this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d())) .translate(pointDouble)); }
Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())).translate( pointDouble));
this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())) .translate(pointDouble));
@Test public void testTransformation() { final Vector3d position = new Vector3d(1, 2, 3); final Quaterniond rotation = Quaterniond.fromAngleDegAxis(90, Vector3d.UNIT_Y); final Vector3d scale = new Vector3d(4, 5, 6); Transform<Extent> transform = new Transform<>(this.mockExtent1, position); assertTransforms(new Vector3d(11, 12, 13), transform, new Vector3d(10, 10, 10)); transform = transform.addScale(scale); assertTransforms(new Vector3d(41, 52, 63), transform, new Vector3d(10, 10, 10)); transform = transform.addRotation(rotation); assertTransforms(new Vector3d(61, 52, -37), transform, new Vector3d(10, 10, 10)); transform = transform.add(transform); assertTransforms(new Vector3d(-158, 254, -354), transform, new Vector3d(10, 10, 10)); }
/** * Creates a new quaternion from the double angles in degrees around the x, y and z axes. * * @param pitch The rotation around x * @param yaw The rotation around y * @param roll The rotation around z * @return The quaternion defined by the rotations around the axes */ public static Quaterniond fromAxesAnglesDeg(double pitch, double yaw, double roll) { return Quaterniond.fromAngleDegAxis(yaw, Vector3d.UNIT_Y). mul(Quaterniond.fromAngleDegAxis(pitch, Vector3d.UNIT_X)). mul(Quaterniond.fromAngleDegAxis(roll, Vector3d.UNIT_Z)); }
/** * Creates a new quaternion from the double angles in degrees around the x, y and z axes. * * @param pitch The rotation around x * @param yaw The rotation around y * @param roll The rotation around z * @return The quaternion defined by the rotations around the axes */ public static Quaterniond fromAxesAnglesDeg(double pitch, double yaw, double roll) { return Quaterniond.fromAngleDegAxis(yaw, Vector3d.UNIT_Y). mul(Quaterniond.fromAngleDegAxis(pitch, Vector3d.UNIT_X)). mul(Quaterniond.fromAngleDegAxis(roll, Vector3d.UNIT_Z)); }
/** * Returns a new transform representing a rotation around an * axis around the origin. The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. * The rotation is around the block center, not the corner. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @return The new rotation transform */ public static DiscreteTransform3 fromRotation(int quarterTurns, Axis axis) { return new DiscreteTransform3(Matrix4d.createRotation(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d()))); }
/** * Adds a rotation to this transform, around an axis, * around the origin and returns it as a new transform. * The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. * The rotation is around the block center, not the corner. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @return The rotated transform as a copy */ public DiscreteTransform3 withRotation(int quarterTurns, Axis axis) { return new DiscreteTransform3(this.matrix.rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d()))); }
/** * Returns a new transform representing a rotation around an axis, * around a given point. The rotation is given is quarter turns. * The actual rotation is {@code quarterTurns * 90}. The block corner * flag change the point to be the block corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The new rotation transform */ public static DiscreteTransform3 fromRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3(Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis .toVector3d())).translate(pointDouble)); }
/** * Adds a a rotation to this transform, around an axis, * around a given point, and returns it as a new transform. * The rotation is given is quarter turns. The actual rotation * is {@code quarterTurns * 90}. The block corner flag changes * the point to be the block upper corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param axis The axis to rotate around * @param point The point of rotation, as block coordinates * @param blockCorner Whether or not to use the corner of the block * instead of the center * @return The rotated transform as a copy */ public DiscreteTransform3 withRotation(int quarterTurns, Axis axis, Vector3i point, boolean blockCorner) { Vector3d pointDouble = point.toDouble(); if (blockCorner) { pointDouble = pointDouble.add(0.5, 0.5, 0.5); } return new DiscreteTransform3( this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(quarterTurns * 90, axis.toVector3d())) .translate(pointDouble)); }
this.matrix.translate(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())) .translate(pointDouble));
Matrix4d.createTranslation(pointDouble.negate()).rotate(Quaterniond.fromAngleDegAxis(halfTurns * 180, axis.toVector3d())).translate( pointDouble));