Creating new numpy scalar through C API and implementing a custom view

Short version Given a built-in quaternion data type, how can I view a numpy array of quaternions as a numpy array of floats with an extra dimension of size 4 (without copying memory)? Long...

Average and Measure of Spread of 3D Rotations

I've seen several similar questions, and have some ideas of what I might try, but I don't remember seeing anything about spread. So: I am working on a measurement system, ultimately computer...

Rotation matrix to quaternion equivalence

I am tracking 3 points (3D, x y z) on a rigid body, which I use to define a local coordinate system. I am using this local coordinate system's orientation (in the global frame of reference) to set...

Writing a Python extension in C, and getting strange memory errors

I have a Python class I've written in C called pyquat.Quat, and it includes methods for multiplying by another Quat, returning a NumPy array (Quat#to_matrix()) and for printing the...

Creating uniform random quaternion and multiplication of two quaternions

I have a python (NumPy) function which creates a uniform random quaternion. I would like to get two quaternion multiplication as 2-dimensional returned array from the same or an another function....

How to multiply two quaternions by python or numpy

I have two quaternions: Q1= w0, x0, y0, z0 and Q2 = w1, x1, y1, z1. I would like to multiply them by using NumPy or Python function which can return 2-d array. I found some pseudocodes on the...

Python: Animating a vector using mplot3d and animation

I'm trying to make a 3d plot with Matplotlib and the animation package from matplotlib. In addition, the animation should be a part of a Gui generated using PyQt and Qt-Designer. Currently I'm...

Trying to use MadgwickAHRS python script, but can't retrieve the new calculated data

I'm working on a project where I want to use madgwick's AHRS filter. I'm trying to use the translated Python code (Jonas Boër, 2015) but I can't get it to work properly. The script can be found...

Reading a Numpy matrix with the python C API

I am writing a C module for python to manipulate coordinates. The coordinates are a 2D Numpy matrix like this: [[x1 y1 z1] [x2 y2 z2] ... [x231, y231, z231]] My code, currently, is here (I left...

Numpy: make batched version of quaternion multiplication

I transformed the following function def quaternion_multiply(quaternion0, quaternion1): """Return multiplication of two quaternions. >>> q = quaternion_multiply([1, -2, 3, 4], [-5, 6, 7,...

Tensorflow segfault when using with numpy-quaternion library

The following code snippet crashes on the second last line, so where tf.train.latest_checkpoint) is called: import tensorflow as tf from tensorflow.contrib.layers.python.layers import batch_norm...

Spring physics applied to quaternions using python

I want to create a simple physics system in python that works on quaternions in a similar fashion as velocity/position. Its main goal is to simulate one object being dragged and try to catch up to...

Writing a fast 3d matrix and vector library in cython

As part of rewriting my game engine in cython, I am trying to improve the performance of my python+numpy classes for matrix and vector math as this was one of the major bottlenecks I had run into...

PyOpenGL Perspective Projection

I'm relatively new to PyOpenGL and started learning about transformations and model, view, and projection matrices. Which was fine until I compiled and ran my code, and found that my object...

An example on why quaternion can prevent gimbal lock

I read this. https://matthew-brett.github.io/transforms3d/gimbal_lock.html and it gave an example of gimbal lock >>> import numpy as np >>> np.set_printoptions(precision=3, suppress=True) # neat...

quaternion creation by spherical coords in numpy

While trying to understand the usage the quaternion extension of numpy, I saw that import numpy as np import quaternion as q theta = np.pi * 1.0 / 3.0 phi =...

quaternion generation with non minimal rotation arc

The quaternion module of numpy can generate quaternion from sperical coordinates. Example: theta = np.pi / 3.0 phi = np.pi / 3.0 qRot = q.from_spherical_coords(theta,phi) qRot quaternion(0.75,...

Spherical interpolation of large numpy array

I have a numpy array which has 8 fields and has 20 million samples. The fields are [time,X,Y,Z,QW,QX,QY,QZ] where x,y,z are spatial points and QW,QX,QY,QZ is a quaternion There are 2 different...

Numpy/Python numerical instability issue multiplying large arrays

I have created a function to rotate a vector by a quaternion: def QVrotate_toLocal(Quaternion,Vector): #NumSamples x Quaternion[w,x,y,z] #NumSamples x Vector[x,y,z] #For example shape...

How to convert Euler angles to Quaternions and get the same Euler angles back from Quaternions?

I am rotating n 3D shape using Euler angles in the order of XYZ meaning that the object is first rotated along the X axis, then Y and then Z. I want to convert the Euler angle to Quaternion and...

3d coordinates x,y,z to 3d numpy array

I have a 3d mask which is an ellipsoid. I have extracted the coordinates of the mask using np.argwhere. The coordinates can be assigned as x, y, z as in the example code. My question is how can I...

pyquaternion: ValueError: Unexpected number of elements in sequence

Using the pyquaternion module I want to obtain a quaternion representation of a 3x3 rotation matrix. When executed, it returns ValueError: Unexpected number of elements in sequence. Got: 3,...

Error state Kalman Filter from MATLAB to Python

I am trying to reproduce the algorithm explained here in Python but I am facing some problems with a strange growth of some parameters. The following is my attempt. Observe that get_ang() and...

How to compute angular velocity using numpy-quaternion

I have a time series, where each measurement is a quaternion. I would like to estimate angular velocity between two measurements. At the moment I use pretty straightforward...

Python - VTK limit rotation of object issue (Quaternion)

I am trying to limit the rotation of the boxwidget by interaction, to enable the user to just rotate the box around the up-axis. Therefore I have tried the approach to add an observer to the...

Figuring out orientation of IMU using accelerometer and magnetometer

I have an IMU, and I am trying to obtain the orientation of it using just the accelerometer and magnetometer. I am using the gravity vector returned from the accelerometer and the vector returned...

Relative camera pose change from global poses

In OpenCV one can estimate the relative rotation and translation of the camera from tracked points using the recoverPose function but I am trying to figure out if one can do something similar...

g2o - what's difference between VertexSE3 and VertexSE3Expmap?

I'm really new to g2o library and I'm struggling to add pose to vertex :( I used the python version of g2o and this is the code I wrote. The type error occus in this line:...

How to find the angles to align X, Y, Z vectors to another coordinate system

I am trying to rotate a group of 3D points (forming a rectangular object) created using GLMeshItem in pyqtgraph and opengl. However, I am having trouble doing this. I need to align the axes of the...

Applying quaternion rotation to a vector time series

I have a time series of 3D vectors in a Python numpy array similar to the following: array([[-0.062, -0.024, 1. ], [-0.071, -0.03 , 0.98 ], [-0.08 , -0.035, 0.991], ...