2 * quat - alculate using quaternions of the form: a + bi + cj + dk
4 * Copyright (C) 1999 David I. Bell
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.2 $
21 * @(#) $Id: quat.cal,v 30.2 2013/08/11 08:41:38 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/cal/RCS/quat.cal,v $
24 * Under source code control: 1990/02/15 01:50:35
25 * File existed as early as: before 1990
27 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
31 * Routines to handle quaternions of the form:
34 * Note: In this module, quaternians are manipulated in the form:
36 * Where s is a scalar and v is a vector of size 3.
40 obj quat {s, v}; /* definition of the quaternion object */
47 x.s = isnull(a) ? 0 : a;
49 x.v[0] = isnull(b) ? 0 : b;
50 x.v[1] = isnull(c) ? 0 : c;
51 x.v[2] = isnull(d) ? 0 : d;
58 print "quat(" : a.s : ", " : a.v[0] : ", " :
59 a.v[1] : ", " : a.v[2] : ")" :;
65 return a.s^2 + dp(a.v, a.v);
71 return sqrt(a.s^2 + dp(a.v, a.v), e);
107 define quat_sub(a, b)
159 define quat_mul(a, b)
166 } else if (!istype(a, x)) {
170 x.s = a.s * b.s - dp(a.v, b.v);
171 x.v = a.s * b.v + b.s * a.v + cp(a.v, b.v);
179 define quat_div(a, b)
188 return a * quat_inv(b);
197 q2 = a.s^2 + dp(a.v, a.v);
204 define quat_scale(a, b)
214 define quat_shift(a, b)
225 if (config("resource_debug") & 3) {
226 print "obj quat {s, v} defined";