From e593583f26f44e74c9ec2797ce8bf8268d26c46c Mon Sep 17 00:00:00 2001 From: L-Nafaryus Date: Tue, 30 Mar 2021 22:14:47 +0500 Subject: [PATCH] Quaternions: another package --- samples/__init__.py | 12 ++++++++++++ src/geometry_utils.py | 10 +++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/samples/__init__.py b/samples/__init__.py index e165fbf..a509690 100644 --- a/samples/__init__.py +++ b/samples/__init__.py @@ -1,6 +1,7 @@ from collections import namedtuple import os, sys import logging +from pyquaternion import Quaternion ROOT = "/home/nafaryus/projects/anisotrope-cube" sys.path.append(ROOT) @@ -33,6 +34,17 @@ def genMesh(stype, theta, flowdirection, saveto): geometry = geometry2 norm = [-1, -1, 1] bcount = 6 + + # initial angle + angle = math.pi / 6 + vec = Quaternion(0, flowdirection[0], flowdirection[1], flowdirection[2]) + ax = Quaternion( + math.cos(angle * 0.5), + math.sin(angle * 0.5) * norm[0], + math.sin(angle * 0.5) * norm[1], + math.sin(angle * 0.5) * norm[2]) + qvec = (ax * vec * ax.inverse).vector + norm = [qvec[0], qvec[1], qvec[2]] #direction = fd([1, 1, 1], [1, -1, 1], [1, -1, -1]) #else: diff --git a/src/geometry_utils.py b/src/geometry_utils.py index e520631..5d2f766 100644 --- a/src/geometry_utils.py +++ b/src/geometry_utils.py @@ -7,7 +7,7 @@ geompy = geomBuilder.New() import math import logging -import quaternion +from pyquaternion import Quaternion import numpy as np @@ -43,8 +43,8 @@ def createGroup(gobj, planelist, grains, name): def createBoundary(gobj, bcount, dvec, norm, grains): - direction = np.quaternion(0, dvec[0], dvec[1], dvec[2]).normalized() - ax = lambda alpha: np.quaternion( + direction = Quaternion(0, dvec[0], dvec[1], dvec[2]).normalized + ax = lambda alpha: Quaternion( np.cos(alpha * 0.5), np.sin(alpha * 0.5) * norm[0], np.sin(alpha * 0.5) * norm[1], @@ -53,7 +53,7 @@ def createBoundary(gobj, bcount, dvec, norm, grains): ang = lambda n, count: 2 * np.pi * n / count limit = bcount if np.mod(bcount, 2) else int(bcount / 2) - vecs = [ ax(ang(n, bcount)) * direction * ax(ang(n, bcount)).inverse() for n in range(limit) ] + vecs = [ ax(ang(n, bcount)) * direction * ax(ang(n, bcount)).inverse for n in range(limit) ] # flowvec = geompy.MakeVector( @@ -62,7 +62,7 @@ def createBoundary(gobj, bcount, dvec, norm, grains): symvec = [] for qvec in vecs: - vec = qvec.vec + vec = qvec.vector symvec.append(geompy.MakeVector( geompy.MakeVertex(0, 0, 0), geompy.MakeVertex(vec[0], vec[1], vec[2])))