## linear algebra – What rotations are used as a reduction step in Kenig-Ruiz-Sogge’s uniform Sobolev estimate?

I think I have understood the bulk of the paper (KRS), but one of the parts I cannot understand is when the authors reduce Theorem 2.1 (p.332) into Proposition 2.1 (p.335). I can understand all the reductions except for the one using a rotation.

In this paper, $$Q$$ is a nonsingular quadratic form on $$mathbb R^n$$, $$nge 3$$, given by$$Q(xi) = -xi_{1}^2-dots-xi_{mathstrut j}^2 + xi_{j+1}^2 + dots xi_{mathstrut n}^2.$$
They apparently say: when $$aneq 0$$ is such that $$Q(a)neq 0$$, it can be rotated while preserving the form of $$Q$$ so that $$ain operatorname{span}((0,dots,0,1))$$ or $$ain operatorname{span}((1,0,dots,0))$$. Why is this true?

With a rotation in the first $$j$$ components and then another in the remaining ones, I can make $$ain operatorname{span}((1,0,dots,0),(0,dots,0,1))$$. So ‘clearly’ I guess I’m missing some sort of rotation that intermingles these two parts of $$Q$$. But what rotations of this type preserve $$Q$$?

Later in the paper near the end, the author specifies in the case where $$Q(D)$$ is the wave operator $$partial_t^2 -Delta$$ that one needs hyperbolic rotations. Do I need to figure out an appropriate group of “rotations” for $$Q$$ in the more general case?

(KRS) Kenig, C. E.; Ruiz, A.; Sogge, C. D., Uniform Sobolev inequalities and unique continuation for second order constant coefficient differential operators, Duke Math. J. 55, 329-347 (1987). ZBL0644.35012.

## shaders – Need help getting an objects orientation / all my OpenGL rotations are reversed

I’m using OpenGL on Ubuntu Linux with the Eclipse IDE and the GCC compiler. I am bringing blender models into a homemade renderer/game engine.
I parse a text file containing object descriptions to load models.

Example object:

``````begin_object generic_object
generic_object_name lampost
generic_object_parent_name world
generic_object_position -10.0000 -10.0000 2.000000
generic_object_rotation 90.000000 0.000000 0.000000
generic_object_scale 1.000000 1.000000 1.000000
end_object

begin_object ...
``````

The `generic_object_rotation 90.000000 0.000000 0.000000` line describes 3 values:

• Rotation around Z (XY).
• Rotation around X (YZ).
• Rotation around Y (XZ).

After going through all the headaches of Euler angles and their gimbal lock and singularities, I switched all my code to quaternions (highly recommended).

I am told that a counter-clockwise rotation around the Z-axis, looking down the Z-axis toward the origin uses a rotation matrix like:

``````cos(theta)  -sin(theta)  0  0
sin(theta)  cos(theta)   0  0
0           0            1  0
0           0            0  1
``````

I got this from a document (rotgen.pdf) off the Song-Ho website.

If I replace `theta` with `+90.0` (just like in my input file above), the result is:

``````  0.0 ,  -1.0 ,  0.0 ,  0.0
1.0 ,   0.0 ,  0.0 ,  0.0
0.0 ,   0.0 ,  1.0 ,  0.0
-10.0 , -10.0 ,  2.0 ,  1.0
``````

So, I make a quaternion for +90.0 degrees, turn it into a matrix and then print out the matrix to see if it is the same, and I actually get the same matrix.

``````  0.0 ,  -1.0 ,  0.0 ,  0.0
1.0 ,   0.0 ,  0.0 ,  0.0
0.0 ,   0.0 ,  1.0 ,  0.0
-10.0 , -10.0 ,  2.0 ,  1.0
``````

All is well… Then, I send this matrix to the shader to draw this object and it rotates my object CW instead.

``````gl_Position = projection_matrix * view_matrix * model_matrix * vec4( aPos , 1.0 );
``````

which seems correct.

So, I made a cube in Blender, attached different colour textures to each side of the cube so I could verify that my input data was good and, as long as the `model_matrix` is the identity matrix, the object is oriented correctly in space. Any time I add rotations, the models rotate in the
opposite direction. This happens on all 3 axes.

My current goal/project is the parenting system. I want to be able to extract orientation and position from the model matrix of any object (that data is stored with the object).

Specifically, right now, I want to extract the forward vector from the `model_matrix` so I can attach a light source to this rotating object. Set its light direction for the fragment shader. That is when I found this error.

What I am seeing:
The rotation of the object is opposite to what I command. When I rotate 0-360 over and over again, the forward vector I am reading from the objects `model_matrix` diverges from the direction of the object until it gets to 180 degrees, where the face of the object and the forward vector are coincident again; then they diverge again until we reach 360 and they are again coincident.

What I expect (and this may be part of my issue):
I want the rotation part of the `model_matrix` that rotates the object to be the current orientation of the object. And it looks like it is but the object does not render that way. The object rotates in the opposite direction (which is preventing me from getting the correct light direction vector, i.e. the forward vector).

Is this an OpenGL thing? Is the orientation of an object the transpose of the 3×3 rotation section of the `model_matrix`?

## macos – How do I reset ios simulator in the given image back to original even after any number of rotations? Basically how to reset it back to normal

rotated simulator pic which has to be reset to normal. If it is in normal state then it turns left or right after my code gets called. How do i write an applescript to always reset it.

Below is my code for rotating it:

``````tell application "System Events"
if menu bar item "Hardware" of menu bar 1 of application process "Simulator" exists then
else
end if
end tell
``````

## 3d – Combining Quaternion Rotations

Multiplying two quaternions gives you a quaternion equivalent to performing the two rotations they represent in sequence.

``````q3 = q1 * q2
q3 * object = q1 * (q2 * object)
// "Perform rotation q2 with respect to the world axes, then q1"
// Or equivalently: "Perform rotation q1 about your local axes, then q2"

q4 = q2 * q1
q4 * object = q2 * (q1 * object)
// "Perform rotation q1 with respect to the world axes, then q2"
// Or equivalently: "Perform rotation q2 about your local axes, then q1"
``````

(Notice that rotating around the object’s local axes – ones that spin with the object – means applying the rotations in the opposite order than if we consider our axes fixed in the world reference frame)

These two possible sequences will generally give different results from one another, and different results from a single rotation along an axis intermediate between the axes of `q1` and `q2`, because 3D rotation is extremely order-dependent.

This isn’t just a quirk of quaternions, but something true of orientations in three-dimensional space themselves.

Our experience from translation might mislead us. With a translation like (+1, +2, +3), we can separate it into…

• a translation by 1 unit along the x axis

• a translation by 2 units along the y axis

• and a translation by 3 units along the z axis

…and perform the three axis-aligned translations one at a time, in any order, and still get the same result of applying the composed translation all at once.

Rotation does not work that way, so an intuition calibrated on translation can easily lead us to false conclusions.

You can verify this for yourself with the axes in your example. Grab an object with an identifiable top/right/front, and mentally map its sides to axes.

• Place it on a table, and find an axis 45 degrees between the x and z axes you picked. Twist the object 45 degrees about that axis, and remember what that orientation looks like.

• Now repeat the experiment, but this time rotate 45 degrees around just the x axis first, then 45 degrees about the z axis, wherever it ends up.

You’ll observe that the orientation you get at the end is different between the two experiments.

Rotation is not simply separable into axis-aligned components.

Or to be more precise: there will be many possible trios of axis-aligned rotations that give the same resulting orientation as any orientation you formed some other way (that’s how Euler angles / Tait-Bryan angles work), but there’s not such a simple mapping between the combined and separated forms like there is for translation. You can’t just take the same angle and repeat it/split it proportionally between the components of its axis and get the same result. The trigonometry of the conversion is messy and has lots of counter-intuitive edge cases. As shown in the link above, sometimes applying a rotation about x and y gives you a rotation about the z!

So, to recap: it is true that to combine rotations expressed as quaternions, all you have to do is multiply those quaternions. But that represents a specific kind of combination, which is composition: applying one rotation, then the other, in sequence.

Our intuition about what this composition should do may depart significantly from the reality, unless we spend a lot of time turning mugs around in our hands. (Just remember to finish your coffee or tea first!)

## group theory – There are operations that are not rotations?

Since reflections in a plane are rotations around some 3D axis, the question is: if the number of dimensions is high enough, there are group operations in the plane that are not reducible to a combination of rotations on some high enough dimension?

For example, some arbitrary permutation of elements.

## unity – How can I use the flags logic to turn on/off the lights and rotations?

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeColors : MonoBehaviour
{
public List<Transform> objectsToRotate = new List<Transform>();
public bool turnOnRotationLights = false;
public float rotationSpeed;
public Light() lights;
public Material material;
public Vector3 targetAngle = new Vector3(-90f, 0f, 0f);

private bool rotationLightsOn = true;

// 0,31,191
// 255,0,0

// Start is called before the first frame update
void Start()
{
if (turnOnRotationLights)
StartCoroutine(SetTrue());
}

// Update is called once per frame
void Update()
{
if(turnOnRotationLights == true && rotationLightsOn == true)
{
StartCoroutine(SetTrue());

rotationLightsOn = false;
}
else
{
rotationLightsOn = true;
}

if (rotationSpeed == 0)
{
for (int i = 0; i < objectsToRotate.Count; i++)
{
Transform t = objectsToRotate(i).transform;
float newAngle = Mathf.LerpAngle(t.localEulerAngles.x, targetAngle.x, Time.deltaTime);
t.localEulerAngles = new Vector3(newAngle, 0, 0);
}
}

if (turnOnRotationLights)
{
for (int i = 0; i < objectsToRotate.Count; i++)
{
objectsToRotate(i).Rotate(new Vector3(Time.deltaTime * rotationSpeed, 0, 0));
}
}
}

public void setHighlight(bool highlight)
{
if (highlight)
{
material.EnableKeyword("_EMISSION");
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
material.SetColor("_EmissionColor", new Color(0, 31, 191));
}
else
{
material.EnableKeyword("_EMISSION");
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
material.SetColor("_EmissionColor", new Color(255,0,0));
}
}

IEnumerator SetTrue()
{
setHighlight(true);

yield return new WaitForSeconds(0.5f);

StartCoroutine(SetFalse());
}

IEnumerator SetFalse()
{
setHighlight(false);

yield return new WaitForSeconds(0.5f);

StartCoroutine(SetTrue());
}
}
``````

It was working fine without the two flags turnOnRotationLights and rotationLightsOn this is how the code looks like before adding and using this two flags :

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChangeColors : MonoBehaviour
{
public List<Transform> objectsToRotate = new List<Transform>();
public float rotationSpeed;
public Light() lights;
public Material material;
public Vector3 targetAngle = new Vector3(-90f, 0f, 0f);

// 0,31,191
// 255,0,0

// Start is called before the first frame update
void Start()
{
StartCoroutine(SetTrue());
}

// Update is called once per frame
void Update()
{
if (rotationSpeed == 0)
{
for (int i = 0; i < objectsToRotate.Count; i++)
{
Transform t = objectsToRotate(i).transform;
float newAngle = Mathf.LerpAngle(t.localEulerAngles.x, targetAngle.x, Time.deltaTime);
t.localEulerAngles = new Vector3(newAngle, 0, 0);
}
}

for(int i = 0; i < objectsToRotate.Count; i++)
{
objectsToRotate(i).Rotate(new Vector3(Time.deltaTime * rotationSpeed, 0, 0));
}
}

public void setHighlight(bool highlight)
{
if (highlight)
{
material.EnableKeyword("_EMISSION");
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
material.SetColor("_EmissionColor", new Color(0, 31, 191));
}
else
{
material.EnableKeyword("_EMISSION");
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
material.SetColor("_EmissionColor", new Color(255,0,0));
}
}

IEnumerator SetTrue()
{
setHighlight(true);

yield return new WaitForSeconds(0.5f);

StartCoroutine(SetFalse());
}

IEnumerator SetFalse()
{
setHighlight(false);

yield return new WaitForSeconds(0.5f);

StartCoroutine(SetTrue());
}
}
``````

but there are two problems :

• When running the game the lights and rotation start at the beginning.
• I can’t control the lights and rotation on/of while the game is running in runtime.

I want :

• When the game start also start the lights and rotation if the public flag is true.
• While the game is running in runtime to be able to turn off/on both lights and rotation.

The way I used it with the flags it’s not working good. When I turn it off at runtime only some orations stop and the lights keep on and it’s all messed.

## algorithms – Cube 3×3: Using just face rotations, transform the cube from configuration A to B

I’m looking for some tips on how to best implement the algorithm to accomplish the following:

• Imagine a 3×3 cube with a rubik’s cube mechanism, i.e. you can freely rotate any of the 6 faces.
• You don’t care about colors.
• Instead you index the component 26 cubes A–Z and ignore the middle.

Illustration image (component cubes): https://paste.pics/AOYUS

Now, I would like to generate a list of face rotations that would get me from this configuration to some other configuration. E. g. this: https://paste.pics/AOYWM

Note: I don’t care which component cubes end up in positions labeled as `*`

Ideally the algorithm produces the shortest list of transformations necessary, but it’s not a firm condition. Any suggestions welcome, thanks!

## c++ – How to efficiently average multiple rotations (quaternions)?

So, I’m working on an animation system in C++, and am trying to blend multiple animations together. A slerp is easy on two quaternions, but is it efficient (or accurate) to chain together for more than two quaternions? I would think there’d be a better way.

I did stumble upon this thread outlining an approach in Unity, but it looks pretty cumbersome, and a lot of it doesn’t translate easily into the code base I’m working with. I have actually implemented the eigenvalue-based approach, but it is very slow. There must be a more efficient way!

## unity – What is wrong with my Saving System ? I’m trying to use json to save objects positions rotations scaling to files

This script is attached to empty GameObject and for testing I dragged two Cubes to the objectsToSave array.

``````using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

{
public Transform() objectsToSave;

private void Awake()
{
SaveSystem.Init();
}

public void Save()
{
SaveObject saveObject = new SaveObject();
for (int i = 0; i < objectsToSave.Length; i++)
{
saveObject.position = objectsToSave(i).position;
saveObject.scaling = objectsToSave(i).localScale;
saveObject.rotation = objectsToSave(i).rotation;

string json = JsonUtility.ToJson(saveObject);
SaveSystem.Save(json);
}
}

{

if (saveString != null)
{
SaveObject saveObject = JsonUtility.FromJson<SaveObject>(saveString);

transform.position = saveObject.position;
transform.localScale = saveObject.scaling;
transform.rotation = saveObject.rotation;
}
}

{

for(int i = 0; i < savedStrings.Count; i++)
{
SaveObject saveObject = JsonUtility.FromJson<SaveObject>(savedStrings(i));

objectsToSave(i).position = saveObject.position;
objectsToSave(i).localScale = saveObject.scaling;
objectsToSave(i).rotation = saveObject.rotation;
}
}

public class SaveObject
{
public Vector3 position;
public Vector3 scaling;
public Quaternion rotation;
}
}
``````

This class make the saving to the file/s :

``````using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public static class SaveSystem
{
private static readonly string SAVE_FOLDER = Application.dataPath + "/save_";
public static void Init()
{
if (!Directory.Exists(SAVE_FOLDER))
{
Directory.CreateDirectory(SAVE_FOLDER);
}
}

public static void Save(string saveString)
{
int saveNumber = 1;
if (!File.Exists(SAVE_FOLDER + "/" + saveNumber + ".txt"))
{
File.WriteAllText(SAVE_FOLDER + "/" + saveNumber + ".txt", saveString);
}
while (File.Exists(SAVE_FOLDER + "/" + saveNumber + ".txt"))
{
saveNumber++;
}
File.WriteAllText(SAVE_FOLDER + "/" + saveNumber + ".txt", saveString);
}

{
DirectoryInfo directoryInfo = new DirectoryInfo(SAVE_FOLDER);
FileInfo() saveFiles = directoryInfo.GetFiles("*.txt");
FileInfo mostRecentFile = null;
foreach (FileInfo fileInfo in saveFiles)
{
if (mostRecentFile == null)
{
mostRecentFile = fileInfo;
}
else
{
if (fileInfo.LastWriteTime > mostRecentFile.LastWriteTime)
{
mostRecentFile = fileInfo;
}
}
}

if (mostRecentFile != null)
{
return saveString;
}
else
{
return null;
}
}

{
DirectoryInfo directoryInfo = new DirectoryInfo(SAVE_FOLDER);
FileInfo() saveFiles = directoryInfo.GetFiles("*.txt");
List<string> savedFiles = new List<string>();
foreach (FileInfo fileInfo in saveFiles)
{
if(savedFile != null)
{
}
}

return savedFiles;
}
}
``````

In the editor in the scene I have 3 buttons one for saving one for loading a single saved file and one for loading all the saved files for all the saved objects in this case two cubes :

The problems I’m facing :

• I can click the Save button many times and it will keep creating new text files even if the cubs didn’t change any position rotation or scaling. The logic is to enable the saving button only when the two cubes or one of the cubes change position or rotation or scaling or all the three.

• When clicking on the Save button I’m not getting any errors but when clicking the Load Single button it does nothing when clicking the Load Multiple button it’s changing one of the cubes and put it on the same position of the other cube and throw this error :

ndexOutOfRangeException: Index was outside the bounds of the array.

Line 51 in the SaveLoad script is :

``````objectsToSave(i).position = saveObject.position;
``````

What I’m trying to do is :

• When clicking the Save button save all the objects in the List objectsToSave position,rotation,scaling each object in the List to have his own text file.

• Enable saving only if one of the objects to save changed position,rotation,scaling one of those or all the three.

• When clicking the Load Multiple button load all the saved positions,rotations,scaling changes made for all the objects to save in the List.

• When clicking Load Single then load the last changed object to save made in the List the most recent changed object in the List.

The idea is later to extend the class for other objects like cameras and others:

``````public class SaveObject
{
public Vector3 position;
public Vector3 scaling;
public Quaternion rotation;
}
``````

## graphics – PyBullet & OpenGL – Rotations are reversed in OpenGL

Project description: I am writing a basic game engine to help with my PhD topic on multi-agent learning. I am using PyBullet as the backend physics engine and OpenGL for visual display. I have OpenGL buffers set up to hold the object information such as position(vec3) and rotation(matrix4x4) with rotations being done using Quaternions, but are stored using Euler angles for convenience.

My problem is that when I rotate an object in the OpenGL game world (around any axis), the pyBullet rotation (as seen from the pyBullet GUI) is in the opposite direction and sometime completely off. I must be missing something quiet basic and I apologies if this is a simple fix. I have also provided a video to show the issue that I am having – link to video of error (Link to video):

When I extract the rotation from PyBullet using `getBasePositionAndOrientation()` and convert the quaternion to Euler angles using `pybullet.getEulerFromQuaternion()`, the result is the correct vec3, but upon conversion to the rotation matrix `pybullet.getMatrixFromQuaternion()`, it seems to reverse the rotation direction.

``````'obj = Class BaseSceneObject'
'action = Euler rotation angle in degrees to apply vec3(x, y, z) e.g.(1., 0., 0.) apply +1 degree rotation to x-axis'

'Collect current position and rotation of object and update PyBullet'
# get the rotation - euler angles in degrees vec3(x,y,z)
rot = obj.get_rotation()
# add rotation action (e.g. +1 degree to x = vec3(1., 0., 0.)) and convert to radians
# convert rotation from euler to quaternion
quat = pybullet.getQuaternionFromEuler(rot)
# update position and orientation
pybullet.resetBasePositionAndOrientation(bodyUniqueId=obj.get_rigid_body_id(),
posObj=obj.get_position(),
ornObj=quat)

'Collect PyBullet results and update OpenGL'
# get position and rotation from PyBullet
position, rotation = pybullet.getBasePositionAndOrientation(bodyUniqueId=obj.get_rigid_body_id())
# update object position
obj.set_position(position=position)
# convert rotation quaternion to euler angles
rot_r = pybullet.getEulerFromQuaternion(rotation)