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.
Diff: vectr.h
- Revision:
- 0:55dbdc9614f8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vectr.h Sat Oct 13 12:22:02 2012 +0000
@@ -0,0 +1,70 @@
+/* Copyright (c) 2011 Alex Allen, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ #ifndef VECTR
+
+#include <iostream>
+using namespace std;
+
+class vectr
+{
+ double x,y,z;
+
+ public:
+
+ vectr(); // initialises vector as all 0s
+ vectr(double num); // initialises vector as all num
+ vectr(double a, double b); // x = a, y = b, z = 0
+ vectr(double a, double b, double c); // x = a, y = b, z = c
+
+ void set(double a, double b, double c); // sets all values of the vector
+ void setx(double a); // sets the x component
+ void sety(double b); // sets the y component
+ void setz(double c); // sets the z component
+
+ double getx(); // gets the x component
+ double gety(); // gets the y component
+ double getz(); // gets the z component
+
+ double mag(); // returns magnitude of the vector
+ double mag2(); // returns magnitude squared of the vector
+
+ vectr unit(); // returns the unit vector
+ vectr operator+(vectr ob2); // output = this + ob2
+ vectr operator-(vectr ob2); // output = this - ob2
+ double operator*(vectr ob2); // output = dot product of this and ob2
+ vectr operator*(double num); // output = this * num
+
+ friend vectr operator*(double num, vectr ob); // output = num * ob
+ vectr operator%(vectr ob2); // output = cross product of this and ob2
+ vectr operator/(double num); // output = this / num
+ friend vectr operator/(double num, vectr ob); // output = num * 1/ob
+
+ // output = dot product of this and 1/ob
+ double operator/(vectr ob2);
+ vectr operator+=(vectr ob2);
+ vectr operator-=(vectr ob2);
+ vectr operator*=(double num);
+ vectr operator/=(double num);
+
+ // output in the form "(x, y, z)"
+ friend ostream &operator<<(ostream &stream, vectr ob);
+};
+
+#define VECTR 1
+#endif
\ No newline at end of file