Skip to content

Instantly share code, notes, and snippets.

View space-cadet's full-sized avatar

Deepak Vaid space-cadet

View GitHub Profile
@space-cadet
space-cadet / QuaternionLog.jl
Created May 18, 2019 06:50
Result of recursively taking log of a quaternion in Julia
recursive_func(q, 100, log)
Quaternion{Float64}(0.0, 0.2138427021361156, 0.6498259226581785, 0.04673029529787405, false)
Quaternion{Float64}(-0.37731329782035117, 0.489868364488579, 1.4886136340169336, 0.10704921468429084, false)
Quaternion{Float64}(0.4796303624933924, 0.5633858732517517, 1.7120188869731483, 0.12311473789246809, false)
Quaternion{Float64}(0.6254684847358931, 0.40893747680176057, 1.242680580247547, 0.0893636717943734, false)
Quaternion{Float64}(0.3735054584912868, 0.35106899793994956, 1.066829652001861, 0.07671787617620018, false)
Quaternion{Float64}(0.1706470491382181, 0.3899604970562924, 1.1850132703548995, 0.08521669900311565, false)
Quaternion{Float64}(0.2327178376780377, 0.44757009502094197, 1.360077510459367, 0.09780592228727658, false)
Quaternion{Float64}(0.37425627242318393, 0.4397353421632598, 1.3362692371178646, 0.09609382123838361, false)
@space-cadet
space-cadet / QuaternionLog.py
Created May 18, 2019 06:43
Result of recursively taking log of a quaternion in Python
recursive_func(Quaternion.random(), 100, Quaternion.log)
0.000 +0.218i -0.344j -0.265k
-0.722 +0.706i -1.112j -0.856k
0.547 +0.900i -1.417j -1.090k
0.730 +0.586i -0.923j -0.710k
0.402 +0.477i -0.751j -0.578k
0.126 +0.543i -0.856j -0.659k
0.195 +0.659i -1.039j -0.799k
0.392 +0.647i -1.019j -0.784k
@space-cadet
space-cadet / MathOverflow.jl
Created May 18, 2019 06:41
Math overflow error in Julia
recursive_func(rand_q[1], 20, exp)
Quaternion{Float64}(0.5640308130993734, 0.4169392317621881, 0.4389478445487356, 0.6341786661544735, false)
Quaternion{Float64}(1.124340976491199, 0.6425229055599401, 0.6764392098021417, 0.9772990598642272, false)
Quaternion{Float64}(0.6707861642901156, 1.4286500959270507, 1.5040630203377152, 2.173025091467643, false)
Quaternion{Float64}(-1.9373469633419282, 0.12737241681125427, 0.1340959150760675, 0.1937377517985787, false)
Quaternion{Float64}(0.1389481946590188, 0.01813389606006181, 0.01909111444176842, 0.02758226892429555, false)
Quaternion{Float64}(1.1482292501280715, 0.020831968042115342, 0.0219316072300202, 0.0316861276174094, false)
Quaternion{Float64}(3.149581083449106, 0.0656539740048246, 0.06911959388823821, 0.09986191389604829, false)
Quaternion{Float64}(23.10433983849076, 1.5266032791987882, 1.6071867740849768, 2.3220151945344782, false)
@space-cadet
space-cadet / MathOverflow.py
Created May 18, 2019 06:39
Result of math overflow error in Python
recursive_func(Quaternion.random(), 10, Quaternion.exp)
0.401 +0.349i +0.310j +0.182k
1.309 +0.500i +0.443j +0.260k
2.792 +1.698i +1.504j +0.884k
-12.401 +7.391i +6.550j +3.847k
-0.000 -0.000i -0.000j -0.000k
1.000 -0.000i -0.000j -0.000k
2.718 -0.000i -0.000j -0.000k
15.154 -0.000i -0.000j -0.000k
@space-cadet
space-cadet / CustomTypesPy37.c
Last active May 17, 2019 06:30
Custom types in Python 3.7. Source code taken from https://docs.python.org/3.7/extending/newtypes.html
// Source: https://docs.python.org/3.7/extending/newtypes.html
typedef struct _typeobject {
PyObject_VAR_HEAD
const char *tp_name; /* For printing, in format "<module>.<name>" */
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
/* Methods to implement standard operations */
destructor tp_dealloc;
// Copyright (c) 2017, Michael Boyle
// See LICENSE file for details: <https://github.com/moble/quaternion/blob/master/LICENSE>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include <Python.h>
#include <numpy/arrayobject.h>
#include <numpy/npy_math.h>
#include <numpy/ufuncobject.h>
#include "structmember.h"
@space-cadet
space-cadet / CustomTypesPy27.c
Last active May 17, 2019 06:29
Creating a custom type in Python. Reference: https://docs.python.org/2/extending/newtypes.html
// Source: https://docs.python.org/2/extending/newtypes.html
#include <Python.h>
typedef struct {
PyObject_HEAD
/* Type-specific fields go here. */
} noddy_NoddyObject;
static PyTypeObject noddy_NoddyType = {
"""
This file is part of the pyquaternion python module
Author: Kieran Wynn
Website: https://github.com/KieranWynn/pyquaternion
Documentation: http://kieranwynn.github.io/pyquaternion/
Version: 1.0.0
License: The MIT License (MIT)
# Original source: https://github.com/JuliaGeometry/Quaternions.jl
struct Quaternion{T<:Real} <: Number
s::T
v1::T
v2::T
v3::T
norm::Bool
end