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.
Dependencies: MPU6050_alter HMC5883L
Diff: Vector/Vector.h
- Revision:
- 2:e6496a794bde
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Vector/Vector.h Fri May 24 05:57:12 2019 +0000
@@ -0,0 +1,56 @@
+#pragma once
+#include "mbed.h"
+
+class Matrix;
+
+class Vector {
+public:
+ Vector(int dim);
+ ~Vector();
+ Vector(const Vector& v);
+
+ Vector& operator=(const Vector& v);
+ Vector operator+();
+ Vector operator-();
+ Vector& operator*=(float c);
+ Vector& operator/=(float c);
+ Vector& operator+=(const Vector& v);
+ Vector& operator-=(const Vector& v);
+
+ void SetComp(int dimNo, float val);
+ void SetComps(float* vals);
+ float GetNorm() const;
+ Vector Normalize() const;
+ Vector GetParaCompTo(Vector v);
+ Vector GetPerpCompTo(Vector v);
+
+ inline int GetDim() const {
+ return dim;
+ }
+
+ inline const float* GetpComponents() const {
+ return (const float*)components;
+ }
+
+ inline float GetComp(int dimNo) const {
+ if (dimNo > dim) error("Index Out of Bounds Error !!");
+ return components[dimNo-1];
+ }
+
+ void CleanUp();
+
+private:
+ int dim;
+ float* components;
+
+ Vector& operator*=(const Matrix& m);
+ Vector& operator*=(const Vector& m);
+};
+
+Vector operator+(const Vector& lhv, const Vector& rhv);
+Vector operator-(const Vector& lhv, const Vector& rhv);
+Vector Cross(const Vector& lhv, const Vector& rhv);
+Vector operator*(const float c, const Vector& rhv);
+Vector operator*(const Vector& lhv, const float c);
+float operator*(const Vector& lhv, const Vector& rhv);
+