## lie algebras – derivation of the derivative of a rotation matrix

I am working on an application of CV, in which a way to calculate the derivative of rotation matrix is involved.

$$R$$ is the rotation matrix and $$R in SO(3)$$
Also, $$R$$ is changing with $$t$$ giving $$R(t)$$.

$$R(t)R(t)^mathrm{T} = I$$ is known. We calculate the derivate of $$R(t)R(t)^mathrm{T}$$ which gives us a skew symmetric matrix $$dot{R(t)}R(t)^mathrm{T}$$ and $$dot{R(t)}R(t)^mathrm{T} = phi(t) hat{}$$, where
$$phi (t) hat{ } = left( begin{matrix} 0 & -phi_3 & phi_2 \ phi_3 & 0 & -phi_1\ -phi_2 & phi_1 & 0 end{matrix} right).$$ Maybe $$phi hat{}$$ is more suitable than $$phi (t) hat{}$$ in the one above.

The derivative of $$R(t)$$ is then given by
$$dot{R(t)} = phi (t) hat{} R(t).$$

To derive the Lie algebra, later, it gives the 1st order expansion of $$R(t)$$
$$R(t) approx R(t_0) + dot{R(t_0)}(t-t_0) = I + phi (t_0) hat{} (t) ,$$
where $$t_0 = 0$$ and $$R(t_0) = I$$.
By given an assumption that $$phi (t_0) = phi_0$$ around $$t_0$$, it gets
$$dot{R(t)} = phi (t_0) hat{} R(t) = phi_0 hat{} R(t).$$
This is the one (problem) I cannot get.
Any suggestion would be appreciated.

Posted on Categories Articles

## 2D – How to make a gun muzzle aim at the mouse when the rotation pivot isn’t on the muzzle?

I’m making a simple 2D shooter game in pygame and I’ve come across an issue when making the character aim its gun at the mouse.

To make the gun aim up and down, I’ve set it so that the gun uses the angle between the x axis and the mouse to rotate itself on its handle. It works just fine but the issue is that since the muzzle of the gun is above the pivot, the muzzle never aims directly at the mouse but slightly higher. My question is, is there a way to compensate for the offset of the muzzle while keeping the rotation pivot on the handle of the gun?

## performance – Rotation Management Application

My code works just fine but it seems like I have too many variables which could confuse people from what the code does. Any ideas? Or does this look fine. Feel free to add any other tips to make my code more efficient.

This subroutine is for a button which when clicked rotates a players position. (The overall program is a rotation management application for football)

``````Private Sub btnConfirmRotation_Click(sender As Object, e As EventArgs) Handles btnConfirmRotation.Click

If comPlayersToBeRotated.SelectedIndex < 0 Then 'If there are no players to be rotated the button does nothing
Exit Sub
End If

Dim lineIndex As Integer = alreadyAdded(comPlayersToBeRotated.SelectedIndex) 'Gets the line index in the text file for the players details
Dim allPlayers As String() = System.IO.File.ReadAllLines(myFile) 'List of all details
Dim entireFile As String = System.IO.File.ReadAllText(myFile) 'String of entire file

Dim playerDetails As String() = allPlayers(lineIndex).Split("|") 'Gets the details of the selected player in the combo box
Dim positionOfPlayerRotating As String = playerDetails(3) 'Assigns position portion of array
Dim rotationOfPlayerRotating As String = playerDetails(2) 'Assigns jersey of person they are rotating with portion of array

For Each line In allPlayers
Dim thisPlayersDetails As String() = line.Split("|") 'The line its on is split into each section of the details
Dim positionOfThisPlayer As String = thisPlayersDetails(3)
Dim jerseyOfThisPlayer As String = thisPlayersDetails(1)
Dim temp As String

If rotationOfPlayerRotating = jerseyOfThisPlayer Then

'Swaps "position"
temp = thisPlayersDetails(3)
thisPlayersDetails(3) = positionOfPlayerRotating
playerDetails(3) = temp

'Rewrites file
entireFile = entireFile.Replace(line, String.Join("|", thisPlayersDetails))
entireFile = entireFile.Replace(allPlayers(lineIndex), String.Join("|", playerDetails))

System.IO.File.WriteAllText(myFile, entireFile) 'Actually writes to file

'Sets to default if items are above zero so i dont get an out of range exception
If comPlayersToBeRotated.Items.Count > 0 Then
comPlayersToBeRotated.SelectedIndex = 0
End If

If lbxPlayers.SelectedIndex >= 0 Then 'If an item is selected
ShowDetails() 'Shows the detail of that player, even if its not the player that rotated so when it is, the details update
End If
End If
Next

'Removes that player from the combo box and adds to already rotated so it won't keep rotating the first player
alreadyAdded.RemoveAt(comPlayersToBeRotated.SelectedIndex)
alreadyRotated.Add(lineIndex)
comPlayersToBeRotated.Items.RemoveAt(comPlayersToBeRotated.SelectedIndex)
End Sub
``````

Posted on Categories Articles

## networking – How to exactly to send game info packets(Player position, rotation, state, etc…) to server, and with what protocol

So the title might be confusing to some but what I fail to figure out how to keep all players perfectly in sync if there are more than lets say 10 players.
So what I am trying to do but I think its a bad idea is for client(player) to send his rotation, position like 50 times a sec to server vid udp. That would keep the server in sync. But the player should also receive other player position and rotation so that would mean 10 packets 50 times a second. Yea I could put that in one packet (array of player info) but that would cause other errors as udp doesn;t always get the packet fully arranged witch would result in corrupt info.(From what I got the bigger it is the more chance for screwup). So how exactly should I plan to do this my approach would be fine for low amount of players, of course I’m not planning on handling 100+ players with my pc but around 20 should be totally manageable.Im just looking for advice on how to improve or totally change my approach. And how to format those packets json, or just raw binary data(not planning on encryption)

Posted on Categories Articles

## Unity ‘Collider.bounds.Intersects’. Does it handle rotation?

You will probably laugh at my code here (and I would love to hear some completely different approaches to this problem if possible), but I’ve written this myself using the only logic I could come up with alone.

Basically I want to make a slope randomly covered with trees. The slope is a quad with a mesh collider (I’ve also tried Box), and the tree is a prefab with just a model and a collider. I iterate through every possible tree location and give it a 0.25 chance of spawning a tree. This all works ok, but since the quad is not lying flat to any axis, I couldn’t think how best to assign the Y-position value to my trees.

My idea was to simply drop the trees all from above and have them land in the quads collider. If I lay the quad flat my code will work fine, but as soon as I tilt the slope the collision is still detected. It seems as if its reading the top of the quads highest point and making a box around it all the way to the bottom.

This is the code:

``````        for (int i = 0; i < trees.Count; i++)
{
if (!trees(i).GetComponent<Collider>().bounds.Intersects(ski_slope.GetComponent<Collider>().bounds))
{
Debug.Log("moving tree");
trees(i).transform.Translate(0, -0.2f, 0);

}
}
``````

So really I think my use of the ‘Intersects’ function must be wrong.

I hope my description of the problem makes sense. Otherwise I can take some screenshots to try show it.

Thank you for any help.

Posted on Categories Articles

## rotation – How to I make MOUSEY look up

I have MOUSEX worked out perfectly, it moves on the X axis, but when I add the Y axis, I can’t use the MOUSEX axis.

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

// This script moves the character controller forward
// and sideways based on the arrow keys.
// It also jumps when pressing space.
// Make sure to attach a character controller to the same game object.
// It is recommended that you make only one call to Move or SimpleMove per frame.

public class Move : MonoBehaviour
{
CharacterController characterController;

public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
public Transform charBody;
private Vector3 moveDirection = Vector3.zero;
public float mouseSense = 11f;
public float runSpeed = 12f;
public bool isRunning = false;
float camRot = 0f;
public Transform altCamera;

void Start()
{
characterController = GetComponent<CharacterController>();
}

void Update()
{
if (characterController.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes

moveDirection = transform.forward * Input.GetAxis("Horizontal") + transform.right * Input.GetAxis("Vertical");
moveDirection *= speed;
moveDirection = transform.right * Input.GetAxis("Horizontal") + transform.right * Input.GetAxis("Vertical");
moveDirection *= speed;

if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}

if (Input.GetKey(KeyCode.LeftShift))
{
moveDirection = transform.forward * Input.GetAxis("Horizontal") + transform.right * Input.GetAxis("Vertical");
moveDirection *= runSpeed;
moveDirection = transform.right * Input.GetAxis("Horizontal") + transform.right * Input.GetAxis("Vertical");
moveDirection *= runSpeed;

}
}

// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
moveDirection.y -= gravity * Time.deltaTime;

// Move the controller
characterController.Move(moveDirection * Time.deltaTime);

float MOUSEY = Input.GetAxis("Mouse Y") * mouseSense * Time.deltaTime;
float MOUSEX = Input.GetAxis("Mouse X") * mouseSense * Time.deltaTime;

charBody.Rotate(Vector3.up * MOUSEX);

}
}
``````

Here’s my code.

but when i add:

``````camRot -= MOUSEY;
transform.localRotation = Quaternion.Euler(camRot, 0f, 0f);
camRot = Mathf.Clamp(camRot, -90f, 90f);
``````

The MOUSEX axis doesn’t work, and the MOUSEY moves up and down, with the MOUSE axis, but doesn’t clamp and the MOUSEX doesn’t rotate.

Help please?

Thanks

## php – When I rotate files and then merge, it loses the rotation

I’m doing some code in PHP / Laravel. I have some code that uses pdfjam to rotate a pdf file by 90Degrees

``````    \$cmd = "pdfjam --outfile \$outputFile --angle \$angle --fitpaper true --rotateoversize true \$inputFile";
\$r = shell_exec(\$cmd);
``````

It works just fine. The file starts out in landscape, I run the above code and look at the file and now it’s portrait.

I also have some code that takes those pdfs and merges them:

``````\$cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile='\$outputFilename'";
foreach(\$fileNames as \$fn) {
\$cmd .= " '\$fn'";
}

shell_exec(\$cmd);
``````

However, once they are merged, they’re back to landscape again!

My first thought was that maybe i’m running the merge too soon after the rotation, not giving the files enough time to save, but no that’s not it. I ran the command on files that were rotated minutes prior and it still came out the wrong orientation after merge.

What’s going on here?

## mathematics – How to check if a point is on the plane given bottom-right point, top-left point, normal and the quaternion rotation of the plane

Let’s assume your quaternion is set up so that it rotates the z+ vector to point along the plane normal, the y+ vector along the rectangle’s “up” axis, and the x+ vector along the rectangle’s “right” axis.

(This is what you’d get in Unity with `Quaternion.LookRotation(planeNormal, Vector3.up)`, for example, assuming you want the rectangle’s vertical axis to align as close to the world up direction as it can. That assumption, and the `Vector3.up` that encodes it, is the fourth piece of information we need, as I was decribing in our chat)

Then we can work this out very simply:

``````Vector3 ClosestPointOnPlane(Vector3 point, Quaternion orientation,
Vector3 topLeft, Vector3 bottomRight) {

Quaternion inverse = Quaternion.Inverse(orientation);

Vector3 inRectangleSpace = inverse * (point - topLeft);

Vector3 limit = inverse * (bottomRight - topLeft);

inRectangleSpace.x = Mathf.Clamp(inRectangleSpace.x, 0, limit.x);
inRectangleSpace.y = Mathf.Clamp(inRectangleSpace.y, limit.y, 0);
inRectangleSpace.z = 0;

return (orientation * inRectangleSpace) + topLeft;
}
``````

Now you can compare the returned point to the one you gave it. If they’re within the threshold you deem “close enough” you can count the point as being in the rectangle.

Because we don’t have infinite-precision real numbers, many points on the rectangle won’t be exactly representable, so doing it this way lets us count points that are not strictly “on” the rectangle, but as close as we can reasonably get with our number format and the rounding in our arithmetic.

Posted on Categories Articles

## Does SOC-2 compliance require password rotation

SOC 2 Type 2 does not have specific technical requirements. What you have to do is to satisfy your assessor.

And if your company cannot satisfy your assessor, then there is a mechanism called “management response” where the company gets to explain away the findings from the assessor.

And if your assessor is 4 years behind in their understanding of best practices in this area, then perhaps you need to find a new assessor …

Posted on Categories Articles

## “Rotation Quaternions must be unit length” using rigidbody.MoveRotation in unity

I’m making a game that involves throwing things with catapults. The cup of a catapult needs to use `Rigidbody.MoveRotation` to let a ball respond to being thrown in the physics engine. I use the following code for my update function(just as a test):

``````void Update()
{
if (Input.GetKey(KeyCode.Space))
{
if (transform.rotation.z > -95.4)
{
Quaternion targetRotation= new Quaternion(0f,0f,(float)(transform.rotation.z-5*Time.deltaTime),0f);
targetRotation=rigidbody.rotation;//rigidbody is a Rigidbody object
targetRotation.z -= 5;
rigidbody.MoveRotation(targetRotation);
}
}
}
``````

This has been giving me the error `Rotation quaternions must be unit length`. I can’t find a reference to that in the unity API, and the one solution I found online was to use the Quaternion’s `normalize` attribute. However, when I did this, the throwing arm rotated 180° almost instantly, and then the same error got thrown a bunch of times. How do I prevent this error from happening, and how do I slow down the rotation?(changing the values doesn’t seem to help). And yes, interpolation is on in the rigidbody component. Let me know if you need more info, thanks!

Posted on Categories Articles