FreePIE icon indicating copy to clipboard operation
FreePIE copied to clipboard

How to add/install numpy to FreePIE?

Open Ratinod opened this issue 7 years ago • 5 comments

copy\paste not work... (of course) "cannot import multiarray from numpy.core" <-- just this. Can you help?

Ratinod avatar Feb 18 '17 21:02 Ratinod

Well, it looks like you're out of luck; the NumPy implementation for IronPython is no longer maintained, and the register method described there doesn't seem to work anymore either. Maybe you can find it somewhere, but you probably have to search for another maths library (that is either written in python or made for IronPython) or write the functions you need yourself (either in python, or in C#).

MarijnS95 avatar Feb 18 '17 22:02 MarijnS95

This is very sad news... This is really bad ... I need a library to work with quaternions... At first I wrote my implementation of quaternions ... But it is not good enough ... Then, I found good library (Quaternion). But it requires numpy. Maybe some one know where to find the Quaternion library without requiring numpy? I find only: "requires numpy" or "without EulerToQuaternion and QuaternionToEuler support" :(

Ratinod avatar Feb 18 '17 22:02 Ratinod

Maybe SlimDX can help you there?

AndersMalmgren avatar Feb 19 '17 23:02 AndersMalmgren

Yep, SlimDX can help you out. However I haven't found a method to convert the quaternion back to euler angles, but you're able to do so using the rotation matrix.

if starting:
	import clr
	clr.AddReference("SlimDX")
	from SlimDX import Quaternion, Matrix
	q = Quaternion.RotationYawPitchRoll(yaw, pitch, roll)
	diagnostics.debug(q)
	m = Matrix.RotationQuaternion(q)

MarijnS95 avatar Feb 20 '17 10:02 MarijnS95

Thanks for the tip (SlimDX), and especially thank you for the example of this in python. Examples of use are very useful when you have no idea at all how to work with it. But without "QuaternionToEuler", I can't use it properly. I'm only a few days studying quaternions, including a rotation matrix. And I have been unable to find an example of using the rotation matrix ... You can find a purely theoretical materials of the formulas (I can't understand how to use them in python), or to find examples in python using "numpy" (again) ... Everywhere is required "numpy". It is very disappointing that you can not take a good, ready implementation of quaternions (like this) and just use it. My realization of the quaternions works badly...

import math

Gyaw = 10
Groll = 10
Gpitch = 10

def degToQuaternion(yaw,roll,pitch):

    y = math.radians(yaw)
    r = math.radians(roll)
    p = math.radians(pitch)
    c1 = round(math.cos(y / 2),6)
    c2 = round(math.cos(r / 2),6)
    c3 = round(math.cos(p / 2),6)
    s1 = round(math.sin(y / 2),6)
    s2 = round(math.sin(r / 2),6)
    s3 = round(math.sin(p / 2),6)
    w = c1*c2*c3 + s1*s2*s3
    x = c1*s2*c3 - s1*c2*s3
    y = c1*c2*s3 + s1*s2*c3
    z = s1*c2*c3 - c1*s2*s3

    return w, x, y, z

def radToQuaternion(y,r,p):

    c1 = round(math.cos(y / 2),6)
    c2 = round(math.cos(r / 2),6)
    c3 = round(math.cos(p / 2),6)
    s1 = round(math.sin(y / 2),6)
    s2 = round(math.sin(r / 2),6)
    s3 = round(math.sin(p / 2),6)
    w = c1*c2*c3 + s1*s2*s3
    x = c1*s2*c3 - s1*c2*s3
    y = c1*c2*s3 + s1*s2*c3
    z = s1*c2*c3 - c1*s2*s3

    return w, x, y, z

def QuaternionToRad(w, x, y, z):
    Eyaw = round(math.atan2(2*(w*z+x*y),1-2*(y*y+z*z)),6)
    Eroll = round(math.atan2(2*(w*x)+(y*z), 1-2*((x*x+y*y))),6)
    Epitch = math.asin(2*(w*y-z*x))
    return Eyaw, Eroll, Epitch

#tests
print(Gyaw, Groll, Gpitch)
print(math.radians(Gyaw), math.radians(Groll), math.radians(Gpitch))
print(degToQuaternion(Gyaw,Groll,Gpitch))
tw, tx, ty, tz = degToQuaternion(Gyaw,Groll,Gpitch)
print(QuaternionToRad(tw, tx, ty, tz))
ty, tr, tp = QuaternionToRad(tw, tx, ty, tz)
print(math.degrees(ty), math.degrees(tr), math.degrees(tp))

Calculations are not accurate. If "Gpitch =90 or -90 or 270 or -270" --> "math domain error". If the angle (any) is greater than 180 degrees, all values take negative (not correct) values. And I want to make that would be controllers are working properly and turned together with the rotation of the head. Video1 Video2

Ratinod avatar Feb 20 '17 13:02 Ratinod