quaternions | This is a library for dealing with quaternions python | Data Manipulation library
kandi X-RAY | quaternions Summary
kandi X-RAY | quaternions Summary
[Build Status] This is a library for dealing with quaternions in python in a unified way. ~~Most of~~ all the quaternions we use are unitary (not like the example above).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Convenience constructor for a quaternion
- Return the first eigenvalue of a matrix
- Average Quaternion
- Compute the center of quaternions
- Returns the cross product of a quaternion
- Return the xi matrix of the quaternion
- Calculate the average and standard deviation between quaternions
- Calculate the covariance matrix from a list of angles
- Calculates the sigma - Leibler divergence coefficient
- Convert ra and roll to quaternion
- Expand a quaternion
- Validates that q is a quaternion
- Exponential exp
- Average Quaternions
- Return the rotation angle in radians
- Return the rotation angle between self and other
- Returns the ra and roll of the ra
- Quaternion first
- Integrate a rotation vector
- Return a unit
- The rotation vector
- Return the log of a quaternion
- Logs the event
- Square norm
quaternions Key Features
quaternions Examples and Code Snippets
Community Discussions
Trending Discussions on quaternions
QUESTION
In Unity project I have to convert Quaternion class to Vector3 and then convert back into Quaternion.
So I wrote the code:
...ANSWER
Answered 2022-Apr-12 at 09:41first off, odd way to debug something in Unity.
And now to the question. Why are you trying to convert something to something else and then back to itself? According to your code you are not changing the created Vector3, so why not just use the original Quaternion?
EulerAngles can't really hold as much information about the rotation of a Quaternion than the Quaternion itself, so It's very likely that information can get lost or altered when working with Eulers.
Here are the two links to Unity-Documentation that you might wanna look at. The first explains, why working with EulerAngles tends to be inconsistent and the other might have a solution for whatever it is you're trying to do.
https://docs.unity3d.com/ScriptReference/Quaternion-eulerAngles.html
https://docs.unity3d.com/ScriptReference/Quaternion-operator_multiply.html
QUESTION
ANSWER
Answered 2021-Dec-20 at 16:06You can create a group:
QUESTION
I have been scratching my head for days understanding how to fully describe a block to insert in DXF. For background I am interested in the rules and behaviour of how to do this, not simply trying to find an existing library.
I can create a block in dxf, lets say this is a simple cube. I can then in the Entities section insert this block. To do this I enter the coordinates relative to the object coordinate system codes:(10, 20, 30), and the normal vector of the object codes:(210,220,230). There is also a value to rotate about the normal vector code: 50.
So there are two things to do:
- Calculate the normal vector for my object
- Calculate the object co-ordinates, given the world coordinates for the object.
To calculate the normal vector, I use quaternions to calculate the rotation applied to the world z-axis (0,0,1) if a yaw, pitch, or roll angle is applied (if not, I simply use the world z-axis). I can use the same quaternions to calculate the arbitrary x and y axis using the same rotation for each of the real world x and y axes. For those looking for more info, this link has a very clear explanation of how to calculate them. https://danceswithcode.net/engineeringnotes/quaternions/quaternions.html
To help you, this calculator can help confirm if this has been implemented correctly or not by checking the results:
Then to calculate the object co-ordinates I simply cross multiply the world coordinate with each of the arbitrary axes/normal axes.
For most scenarios this appears to work. However I am left at a loss for additional rules and requirements which I cannot see documented anywhere:
If only a yaw angle is applied (rotation about z), then the normal is still (0,0,1). We need to apply a rotation about z in the scenario that pitch and roll are zero.
If I alter the pitch, the normal vector can change from a negative y-coordinate to a positive one. This change in slope appears to affect the direction the vector is headed and if positive, requires a rotation about the normal of 180 degrees to correct it.
For some unknown reason when I apply a roll angle, my object is rotated around the normal by 90 degrees, and I need to apply a correction here.
I am struggling to find any more clear direction on this online. Does anyone have any thorough explanations that describe the behaviour above, or any pointer material?
...ANSWER
Answered 2022-Mar-09 at 06:32As suggested in another topic, a little matrix calculus can solve this issue.
Shortly, they are mainly two ways to describe the same Euler angles:
- Tait-Bryan angles (yaw, pitch, roll) rotations about X, Y, Z axis;
- Proper Euler angles (precession, nutation, intrisic rotation) rotations about Z, X, Z axis; AutoCAD uses the second one to describe a bloc orientation. The combination of precession and nutation provides the OCS transformation matrix and the intrinsic rotation is the rotation value of the block.
A little F# example with 3x3 matrices to describe 3d rotations.
QUESTION
I wish to make a turret in a 2d game, which should rotate smoothly to the angle of the mouse. I came up with two solutions but neither are satifactory. The first:
...ANSWER
Answered 2022-Feb-17 at 14:38I found a cheesed solution, after a long time! This was oddly challenging. I still feel like my solution was sub-optimal though
It just checks which way is shorter
QUESTION
I have a gltf model of my robot loaded in A-frame scene version 1.0.4. So far I can turn the robot about its x,y, z axes, but when I try to move it forward it still moves in its initial direction rather than the direction it's facing. I want to be able to control its movements with my keyboard without using any external libraries. I believe I have to use Quaternions, but I haven't figured out how to use them yet. Here is my A-frame code so far.
...ANSWER
Answered 2022-Feb-05 at 18:56Yes, using quatenions is a good way to solve this.
You can simply apply the robot's current quaternion to a vector3 representing the movement you want to make in the robt's original rotation, and apply that to the robot's position.
Something like this:
QUESTION
Similar to these two previous questions (How to calculate all 24 rotations of 3d array?, How to get all 24 rotations of a 3-dimensional array?), I want to find the all the 90 degree rotations of an object. However, I need the quaternions of those rotations.
...ANSWER
Answered 2022-Jan-18 at 23:23import numpy as np
import itertools
from pyquaternion import Quaternion
def rotations():
for x, y, z in itertools.permutations([0, 1, 2]):
for sx, sy, sz in itertools.product([-1, 1], repeat=3):
rotation_matrix = np.zeros((3, 3))
rotation_matrix[0, x] = sx
rotation_matrix[1, y] = sy
rotation_matrix[2, z] = sz
if np.linalg.det(rotation_matrix) == 1:
quat = Quaternion(matrix=rotation_matrix)
yield quat.elements
all_rotations = list(rotations())
print(len(all_rotations))
for x in all_rotations:
print(x)
QUESTION
Scenario
I'm using unity c# to re-invent a google-earth like experience as a project. New tiles are asynchronously loaded in from the web while a user pans the camera around the globe. So far I'm able to load in all the TMS tiles based on their x & y coordinates and zoom level. Currently I'm using tile x,y to try and figure out where the tile should appear on my earth "sphere" and it's becoming quite tedious, I assume because of the differences between Euler angles and quaternions.
- I'm using the angle of
Camera.main
to figure out which tiles should be viewed at any moment (seems to be working fine) - I have to load / unload tiles for memory management as level 10 can receive over 1 million 512x512 tiles
- I'm trying to turn a downloaded tile's x,y coordinates (2d) into a 3d position & rotation
Question
Using just the TMS coordinates of my tile (0,0 - 63,63) how can I calculate the tile's xyz "earth" position as well as its xyz rotation?
Extra
- in the attached screenshot I'm at zoom level 4 (64 tiles)
- y axis 0 is the bottom of the globe while y axis 15 is the top
- I'm mostly using
Mathf.Sin
andMathf.Cos
to figure out position & rotation so far
I've figured out how to get the tile position correct. Now I'm stuck on the correct rotation of the tiles.
The code that helped me the most was found with a question about generating a sphere in python.
I modified to the code to look like so:
...ANSWER
Answered 2021-Dec-07 at 21:20For the positioning and rotation of the planes, you can do that in c#:
QUESTION
Mac Big Sur C++ OpenGL attempting to learn quaternions from a tutorial.
The gtx headers are under usr/local/include/glm
.
Can anyone figure out what is wrong with my header includes or header search path? Thanks.
Minimum reproducible code that fails for this issue:
...ANSWER
Answered 2022-Jan-06 at 05:46In tutorial 1 of the link in the comment, the author introduces
QUESTION
Story
so I'm working on making a procedural terrain generator script to spawn rocks on the ground all the big rocks don't care what rotation they are but I have some small rocks that have to be parallel to the terrain or they look weird, part of them floating off the ground other part stuck in the ground the quaternions I don't seem to understand
Problem
i am getting the terrainData.GetInterpolatedNormal and putting it into a vector3 called normals then when i am spawning my rock i rotate it towards ground
ANSWER
Answered 2022-Jan-05 at 04:42Quaternions use compound(Imaginary) numbers to represent a sequence of rotations in 3d space.
When you instantiate a new Quaternion
using it's constructor you are providing it with what you think the Quaternion
's real and imaginary numbers should be.
Despite the seemingly familiar x
, y
, and z
names you should not manually modify or provided them, they are not euler angles, cartesian coordinates, or traditional vector components.
What you're currently passing it is portions of a direction instead of the real and imaginary parts of a Quaternion
.
A normal is an "outwards direction" from a given position. So to get a rotation we need some other direction to compare it to in order to get a rotation.
Compare your direction with the up direction and you'll get a rotation that you can use.
QUESTION
Scenario:
- Parent P1 has Child C1
- Target exists
- All items' forward vectors face perfectly parallel to the X-Z Plane (pseudo 2D)
- Positions of all objects are arbitrary
- Child will never move on its own within Parent's space
Goal:
Rotate P1 exclusively about the Y-Axis to have C1 Face the opposite direction of target's forward vector
Note: Y-Axis Positive would face reader, Negative would go into screen
Implementation:
...ANSWER
Answered 2022-Jan-03 at 07:17A simple way of representing this transform would be the targets rotation plus 180 degrees about the up axis, and that can be expressed as follows:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install quaternions
You can use quaternions like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page