Mercurial > hg > soniczoomios
annotate 2dvector.mm @ 49:178642d134a7 tip
xtra files
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 01 May 2013 17:34:33 +0100 |
parents | 43df75088d85 |
children |
rev | line source |
---|---|
rt300@0 | 1 /* |
rt300@0 | 2 * 2dvector.cpp |
rt300@0 | 3 * simplespring |
rt300@0 | 4 * |
rt300@0 | 5 * Created by Robert Tubb on 01/06/2011. |
rt300@0 | 6 * Copyright 2011 __MyCompanyName__. All rights reserved. |
rt300@0 | 7 * |
rt300@0 | 8 */ |
rt300@0 | 9 |
rt300@0 | 10 #include "2dvector.h" |
rt300@3 | 11 |
rt300@0 | 12 |
rt300@0 | 13 TwoVector::TwoVector(){ |
rt300@0 | 14 x = 0.0; |
rt300@0 | 15 y = 0.0; |
rt300@0 | 16 //cout << "def constr set vector to zeros" << endl; |
rt300@0 | 17 } |
rt300@0 | 18 |
rt300@0 | 19 TwoVector::TwoVector(double ax, double ay){ |
rt300@0 | 20 x = ax; |
rt300@0 | 21 y = ay; |
rt300@0 | 22 //cout << "spec constr set vector to " << ax << "," << ay << endl; |
rt300@0 | 23 } |
rt300@0 | 24 |
rt300@0 | 25 double TwoVector::norm(){ |
rt300@0 | 26 double norm; |
rt300@0 | 27 norm = sqrt(x * x + y * y); |
rt300@0 | 28 return norm; |
rt300@0 | 29 |
rt300@0 | 30 } |
rt300@0 | 31 |
rt300@0 | 32 void TwoVector::setCoord(double ax, double ay){ |
rt300@0 | 33 x = ax; |
rt300@0 | 34 y = ay; |
rt300@0 | 35 |
rt300@0 | 36 } |
rt300@0 | 37 |
rt300@0 | 38 TwoVector TwoVector::minus(TwoVector otherPoint){ |
rt300@0 | 39 TwoVector diff; |
rt300@0 | 40 diff.setCoord(x - otherPoint.x, y - otherPoint.y); |
rt300@0 | 41 return diff; |
rt300@0 | 42 } |
rt300@0 | 43 |
rt300@0 | 44 TwoVector TwoVector::operator-(TwoVector otherPoint){ |
rt300@0 | 45 TwoVector diff; |
rt300@0 | 46 diff.setCoord(x - otherPoint.x, y - otherPoint.y); |
rt300@0 | 47 return diff; |
rt300@0 | 48 } |
rt300@0 | 49 |
rt300@0 | 50 TwoVector TwoVector::operator*(TwoVector otherPoint){ // if multiplying two vectors - elementwise |
rt300@0 | 51 TwoVector diff; |
rt300@0 | 52 diff.setCoord(x * otherPoint.x, y * otherPoint.y); |
rt300@0 | 53 return diff; |
rt300@0 | 54 } |
rt300@0 | 55 |
rt300@3 | 56 TwoVector TwoVector::operator*(const double& scalar){ |
rt300@0 | 57 TwoVector diff; |
rt300@0 | 58 diff.setCoord(x * scalar, y * scalar); |
rt300@0 | 59 return diff; |
rt300@0 | 60 } |
rt300@0 | 61 |
rt300@0 | 62 TwoVector TwoVector::operator+(TwoVector otherPoint){ |
rt300@0 | 63 TwoVector diff; |
rt300@0 | 64 diff.setCoord(otherPoint.x + x, otherPoint.y + y); |
rt300@0 | 65 return diff; |
rt300@0 | 66 } |
rt300@3 | 67 |
rt300@0 | 68 /* |
rt300@0 | 69 TwoVector TwoVector::operator=(TwoVector otherPoint){ |
rt300@0 | 70 TwoVector result; |
rt300@0 | 71 result.setCoord(otherPoint.x, otherPoint.y); |
rt300@0 | 72 return result; |
rt300@0 | 73 } |
rt300@0 | 74 */ |
rt300@0 | 75 double TwoVector::distanceTo(TwoVector otherPoint){ |
rt300@0 | 76 TwoVector diff; |
rt300@0 | 77 diff.setCoord(otherPoint.x - x, otherPoint.y - y); |
rt300@0 | 78 return diff.norm(); |
rt300@0 | 79 } |
rt300@0 | 80 |