Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LSM303DLH_Example Arch_Test
Diff: Vector.h
- Revision:
- 0:9b2a0b783bfc
diff -r 000000000000 -r 9b2a0b783bfc Vector.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Vector.h Thu Oct 06 08:38:06 2011 +0000
@@ -0,0 +1,47 @@
+#ifndef VECTOR_H
+#define VECTOR_H
+
+#include "mbed.h"
+
+class Vector {
+public:
+ float x, y, z;
+
+ Vector(): x(0), y(0), z(0) {}
+
+ Vector(float x, float y, float z) : x(x), y(y), z(z) {}
+
+ Vector(const Vector& v) {
+ x = v.x, y = v.y, z = v.z;
+ }
+
+ Vector product(const Vector& v) {
+ return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
+ }
+
+ float dot(const Vector& v) {
+ return x * v.x + y * v.y + z * v.z;
+ }
+
+ Vector scale(const float c) {
+ return Vector(c * x, c * y, c * z);
+ }
+
+ float norm() {
+ return sqrt(x * x + y * y + z * z);
+ }
+
+ Vector operator*(const Vector& v) {
+ return product(v);
+ }
+
+ Vector operator /=(float c) {
+ return *this = scale(1 / c);
+ }
+
+ Vector operator *=(float c) {
+ return *this = scale(c);
+ }
+};
+
+#endif
\ No newline at end of file