Mirroring Rotations

Hello,

I’ve really been blasting this forum with questions lately. My apologies and thanks to all the kind folks who have helped. I’m an artist first and C# coder 4th…

I have object A which is rotating on the x,y,z. I want object B to rotate as well but as if mirrored. In other words when A rotates on the x -45, B should rotate on the x 45. When A rotates on they y 25, B should rotate on the y -25. But when A rotates on the z 45, B should also rotate on the z 45.

I’m having a bit of trouble figuring out this Euler and Quaternion jazz in C#. Any help is greatly appreciated. Thanks again.

Rotations are far from my specialty, but does work?

Quaterion brot = Quaterion.Euler(new Vector3(arot.x, arot.y) * -1, arot.z)); // where arot is a.rotation
// err, or I could have written B.rotation =

Hi thanks. Not sure if I got the code right. The console gave me the error “Euler takes two arguments.” Here’s what I wrote:

public Transform _head;
public Transform headTarget;

headTarget.rotation = Quaternion.Euler(new Vector3(_head.rotation.x, _head.rotation.y) * -1, _head.rotation.z);

Also tried this. Kills the error but doesn’t work.

headTarget.rotation = Quaternion.Euler(new Vector3(_head.rotation.x * -1, _head.rotation.y * -1, _head.rotation.z));

//Also tried this (below).  Works a bit but rotates the object in a strange way...

headRotX = _head.eulerAngles.x * -1;
        headRotY = _head.eulerAngles.y *-1;
        headRotZ = _head.eulerAngles.z;
        headTarget.eulerAngles = new Vector3(headRotX,headRotY, headRotZ);

Quaternion.Inverse:

The inverse quaternion is a rotation that when appended to the input results in no/identity rotation.

Basically if you have a rotation of X degrees around some axis, the inverse will be -X degrees around the same axis.

If this is what you mean by ‘mirror’, then that’s what you get.

Though technically that’s ‘inverse’.

‘mirror’ actually has a definition, in math it’s called ‘reflection’. It’s where points are isometric to one another over some hyperplane (an axis in 2d, a plane in 3d).

Since it’s to do with isometric positions… I’d assume what you mean by a reflection rotation, is a rotation that when applied to a vector would give you its reflected position over some hyperplane.

SO… what you’ll need to do is first and foremost… define your plane of reflection.

From the description you give about reflecting the x and y euler’s, but not the z… the plane must be the plane that intersects both the x and y axis.

Once you have that, you should be able to follow this:
http://www.euclideanspace.com/maths/geometry/affine/reflection/quaternion/index.htm

3 Likes

Yes I think I mistyped mine, but if your second post, that looks more or less how I would have done it.
Now, I’m rethinking… and… Here we go… :slight_smile:

test2.transform.rotation = Quaternion.Euler(test.transform.eulerAngles.x * -1, test.transform.eulerAngles.y * -1, test.transform.eulerAngles.z);

Tested… works :slight_smile:

Edit: For clarification, as I read that my first attempt failed (despite the correct of syntax), I knew that I was trying to use Quaterion bits directly ( I think : ie: rotation.x). Oops :slight_smile:

1 Like

Haha. Thanks for the reply. This is a bit intense for just wanting to set two rotation values (x,y) to negative? Um, had a look at the link. Like I said artist first, coder fourth. There must be a simpler way to do this? Thanks again.

Edit: I now see why a reflection plane is required.

Thanks. This does in fact work, but I’m starting to see why a mirror plane would be of essence given that my two shapes are not directly aligned. But technically your code did what I was asking. Thank you.

I now see why a reflection plane is required but can you please go into more detail about setting this up? Thanks again.

Eh, np… Good luck with your stuff :slight_smile: