Quaternion operations

I want to preface by saying this is homework but any general advice is appreciated. I'm trying to write a program (a .cpp file and a header file) that when when coupled with this .cpp file:
-----------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "quaternion.h"

int main (int argc, char *argv[])
{
	quaternion 
				a = quaternion (1), 
				b = quaternion (2, 5, 3.2, -2.15), 
				c = quaternion (0, -2.1, -0.34, 1.035);

	cout << "a " << a << "  b " << b << "  c " << c << endl;
	cout << "b+c: " << b + c << endl;
	cout << "c-b: " << c - b << endl;
	cout << "b*c: " << b * c << endl;
	cout << "c*b: " << c * b << endl;
	quaternion d = b / c;
	cout << "b/c: " << d << " (and ans * c: " << d * c << ")\n";
	cout << "Mess: " << a + b / c - (b-a) / (a + c) << endl; 

	return 0;
}

------------------------------------------
will result in the following output:

1
2
3
4
5
6
7
a 1+0i+0j+0k  b 2+5i+3.2j+-2.15k  c 0+-2.1i+-0.34j+1.035k
b+c: 2+2.9i+2.86j+-1.115k
c-b: -2+-7.1i+-3.54j+3.185k
b*c: 13.8133+-1.619i+-1.34j+7.09k
c*b: 13.8133+-6.781i+-0.02j+-2.95k
b/c: -2.46805+0.289271i+0.239421j+-1.26679k (and ans * c: 2+5i+3.2j+-2.15k)
Mess: 0.474285+-0.395755i+-0.397248j+-0.0230095k

these are directions http://i.imgur.com/YZE4IJV.jpg

This is what I have written so far:
http://pastebin.com/dgWUecDr

Edit: Directions include info about "ij", "jk", "ik", "i2", "j2", and "k2" and added what I have so far.
Last edited on
What have you written so far? By the way, your linked directions don't say how to evaluate "ij", "jk", "ik", "i2", "j2", or "k2".
Added info about how to evaluate "ij", "jk", "ik", "i2", "j2", and "k2" and included what I have so far.
Quaternions are fun. See http://en.wikipedia.org/wiki/Quaternion

@xeonn:
What you have written so far does neither fulfill requirements (for that part) nor is syntactically correct.

* What member variables must a quaternion have? (You have 5 members.)
* What constructers you are expected to have?
* How should one initialize member variables in a constructor?

* Do you know how to overload operator<< ?
What's in the directions is 100 percent of it, the rest is just turn in info. I know what I have so far is incorrect, it's the best I can do so far without asking the instructor. If I could be more specific id say the problem is trying to find out how to use constructors to add values in the same way one might add large numbers on paper, vertically but without carrying values of 10 over. Thank you for your response.


If I could be more specific id say the problem is trying to find out how to use constructors to add values in the same way one might add large numbers on paper, vertically but without carrying values of 10 over. Thank you for your response.


I'm not sure what you're saying, since you're not supposed to be adding anything in your constructors. By the way, I factored out the multiplication last night, it should be helpful:

1
2
3
4
5
6
7
8
/*
	(A + Bi + Cj + Dk) x (Z + Yi + Xj + Wk)
	AZ + AYi + AXj + AWk + BZi + BYi^2 + BXij + BWik + CZj + CYji + CXj^2 + CWjk + DZk + DYki + DXkj + DWk^2
	AZ + AYi + AXj + AWk + BZi - BY + BXij + BWik + CZj + CYji - CX + CWjk + DZk + DYki + DXkj - DW
	AZ + AYi + AXj + AWk + BZi - BY + BXk - BWj + CZj - CYk - CX + CWi + DZk + DYj - DXi - DW
	AZ - BY - CX - DW + AYi + BZi + CWi - DXi + AXj - BWj + CZj + DYj + AWk + BXk - CYk + DZk
	AZ - BY - CX - DW + i * (AY + BZ + CW - DX) + j * (AX - BW + CZ + DY) + k * (AW + BX - CY + DZ)
*/
Topic archived. No new replies allowed.