reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofVec2f.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofMath.h"
4#include "ofMathConstants.h"
5#include "ofConstants.h"
6#include "glm/vec2.hpp"
7#include "glm/fwd.hpp"
8#include <cmath>
9
10class ofVec3f;
11class ofVec4f;
12
72class ofVec2f {
73public:
75 static const int DIM = 2;
77
79 float x;
80
82 float y;
83
84 //---------------------
87
97
99 explicit ofVec2f( float scalar );
100
111 ofVec2f( float x, float y );
112
121 ofVec2f( const ofVec3f& vec );
122
131 ofVec2f( const ofVec4f& vec );
132
134
135 ofVec2f(const glm::vec2 & v);
136 ofVec2f(const glm::vec3 & v);
137 ofVec2f(const glm::vec4 & v);
138
139 operator glm::vec2() const;
140
141 //---------------------
144
145
159 float * getPtr() {
160 return (float*)&x;
161 }
162
163 const float * getPtr() const {
164 return (const float *)&x;
165 }
166
177 float& operator[]( int n ){
178 return getPtr()[n];
179 }
180
181 float operator[]( int n ) const {
182 return getPtr()[n];
183 }
184
185
186
191 //#include "glm/fwd.hpp"
195 void set( float x, float y );
196
205 void set( const ofVec2f& vec );
206
207 void set( float scalar );
208
210
211 //---------------------
214
215
229 bool operator==( const ofVec2f& vec ) const;
230
244 bool operator!=( const ofVec2f& vec ) const;
245
260 bool match( const ofVec2f& vec, float tolerance = 0.0001f ) const;
261
272 bool isAligned( const ofVec2f& vec, float tolerance = 0.0001f ) const;
273
278 bool isAlignedRad( const ofVec2f& vec, float tolerance = 0.0001f ) const;
279
290 bool align( const ofVec2f& vec, float tolerance = 0.0001f ) const;
291
296 bool alignRad( const ofVec2f& vec, float tolerance = 0.0001f ) const;
297
299
300 //---------------------
303
304
312 ofVec2f operator+( const ofVec2f& vec ) const;
313
320 ofVec2f operator+( const float f ) const;
321
329 ofVec2f& operator+=( const ofVec2f& vec );
330
337 ofVec2f& operator+=( const float f );
338
346 ofVec2f operator-( const ofVec2f& vec ) const;
347
354 ofVec2f operator-( const float f ) const;
355
363
371 ofVec2f& operator-=( const ofVec2f& vec );
372
379 ofVec2f& operator-=( const float f );
380
391 ofVec2f operator*( const ofVec2f& vec ) const;
392
400 ofVec2f operator*( const float f ) const;
401
411 ofVec2f& operator*=( const ofVec2f& vec );
412
419 ofVec2f& operator*=( const float f );
420
430 ofVec2f operator/( const ofVec2f& vec ) const;
431
439 ofVec2f operator/( const float f ) const;
440
450 ofVec2f& operator/=( const ofVec2f& vec );
451
458 ofVec2f& operator/=( const float f );
459
460
462 friend std::ostream& operator<<(std::ostream& os, const ofVec2f& vec);
463 friend std::istream& operator>>(std::istream& is, const ofVec2f& vec);
465
467
468 //---------------------
471
481 ofVec2f getScaled( const float length ) const;
482
491 ofVec2f& scale( const float length );
492
493
504 ofVec2f getRotated( float angle ) const;
505
509 ofVec2f getRotated( float angle, const ofVec2f& pivot ) const;
510
520
524 ofVec2f getRotatedRad( float angle, const ofVec2f& pivot ) const;
525
526
536
538 ofVec2f& rotate( float angle, const ofVec2f& pivot );
539
549
551 ofVec2f& rotateRad( float angle, const ofVec2f& pivot );
552
553
554
565 ofVec2f getMapped( const ofVec2f& origin,
566 const ofVec2f& vx,
567 const ofVec2f& vy ) const;
568
569
579 ofVec2f& map( const ofVec2f& origin,
580 const ofVec2f& vx, const ofVec2f& vy );
581
582
584
585
586 //---------------------
589
611 float distance( const ofVec2f& pnt) const;
612
633 float squareDistance( const ofVec2f& pnt ) const;
634
636
637 //---------------------
640
661 ofVec2f getInterpolated( const ofVec2f& pnt, float p ) const;
662
682 ofVec2f& interpolate( const ofVec2f& pnt, float p );
683
695 ofVec2f getMiddle( const ofVec2f& pnt ) const;
696
709 ofVec2f& middle( const ofVec2f& pnt );
710
730 ofVec2f& average( const ofVec2f* points, std::size_t num );
731
733
734 //---------------------
737
752
768
769
770
786 ofVec2f getLimited(float max) const;
787
788
801 ofVec2f& limit(float max);
802
803
805
806 //---------------------
809
810
826 float length() const;
827
843 float lengthSquared() const;
844
854 float angle( const ofVec2f& vec ) const;
855
865 float angleRad( const ofVec2f& vec ) const;
866
868
869 //---------------------
872
886
899
930 float dot( const ofVec2f& vec ) const;
931
932
934
935
936
937 //---------------------------------------------------
938 // this methods are deprecated in 006 please dont use:
940
941 // getScaled
942 OF_DEPRECATED_MSG("Use member method getScaled() instead.", ofVec2f rescaled( const float length ) const);
943
944 // scale
945 OF_DEPRECATED_MSG("Use member method scale() instead.", ofVec2f& rescale( const float length ));
946
947 // getRotated
948 OF_DEPRECATED_MSG("Use member method getRotated() instead.", ofVec2f rotated( float angle ) const);
949
950 // getNormalized
951 OF_DEPRECATED_MSG("Use member method getNormalized() instead.", ofVec2f normalized() const);
952
953 // getLimited
954 OF_DEPRECATED_MSG("Use member method getLimited() instead.", ofVec2f limited(float max) const);
955
956 // getPerpendicular
957 OF_DEPRECATED_MSG("Use member method getPerpendicular() instead.", ofVec2f perpendiculared() const);
958
959 // getInterpolated
960 OF_DEPRECATED_MSG("Use member method getInterpolated() instead.", ofVec2f interpolated( const ofVec2f& pnt, float p ) const);
961
962 // getMiddled
963 OF_DEPRECATED_MSG("Use member method getMiddled() instead.", ofVec2f middled( const ofVec2f& pnt ) const);
964
965 // getMapped
966 OF_DEPRECATED_MSG("Use member method getMapped() instead.", ofVec2f mapped( const ofVec2f& origin, const ofVec2f& vx, const ofVec2f& vy ) const);
967
968 // squareDistance
969 OF_DEPRECATED_MSG("Use member method squareDistance() instead.", float distanceSquared( const ofVec2f& pnt ) const);
970
971 // use getRotated
972 OF_DEPRECATED_MSG("Use member method getRotated() instead.", ofVec2f rotated( float angle, const ofVec2f& pivot ) const);
973
974 // return all zero vector
975 static ofVec2f zero() { return ofVec2f(0, 0); }
976
977 // return all one vector
978 static ofVec2f one() { return ofVec2f(1, 1); }
979
981};
982
983
984
986
987// Non-Member operators
988//
989ofVec2f operator+( float f, const ofVec2f& vec );
990ofVec2f operator-( float f, const ofVec2f& vec );
991ofVec2f operator*( float f, const ofVec2f& vec );
992ofVec2f operator/( float f, const ofVec2f& vec );
993
994
996
997
998
999
1001// Implementation
1004
1005
1006inline ofVec2f::ofVec2f(): x(0), y(0) {}
1007inline ofVec2f::ofVec2f( float _scalar ): x(_scalar), y(_scalar) {}
1008inline ofVec2f::ofVec2f( float _x, float _y ):x(_x), y(_y) {}
1009inline ofVec2f::ofVec2f(const glm::vec2 & v): x(v.x), y(v.y) {}
1010
1011// Getters and Setters.
1012//
1013//
1014inline void ofVec2f::set( float _scalar ) {
1015 x = _scalar;
1016 y = _scalar;
1017}
1018
1019inline void ofVec2f::set( float _x, float _y ) {
1020 x = _x;
1021 y = _y;
1022}
1023
1024inline void ofVec2f::set( const ofVec2f& vec ) {
1025 x = vec.x;
1026 y = vec.y;
1027}
1028
1029inline ofVec2f::operator glm::vec2() const{
1030 return glm::vec2(x,y);
1031}
1032
1033// Check similarity/equality.
1034//
1035//
1036inline bool ofVec2f::operator==( const ofVec2f& vec ) const {
1037 return (x == vec.x) && (y == vec.y);
1038}
1039
1040inline bool ofVec2f::operator!=( const ofVec2f& vec ) const {
1041 return (x != vec.x) || (y != vec.y);
1042}
1043
1044inline bool ofVec2f::match( const ofVec2f& vec, float tolerance ) const {
1045 return (fabs(x - vec.x) < tolerance)
1046 && (fabs(y - vec.y) < tolerance);
1047}
1048
1049//
1050// Checks if vectors look in the same direction.
1051// Tolerance is specified in degree.
1052
1053inline bool ofVec2f::isAligned( const ofVec2f& vec, float tolerance ) const {
1054 return fabs( this->angle( vec ) ) < tolerance;
1055}
1056inline bool ofVec2f::align( const ofVec2f& vec, float tolerance ) const {
1057 return isAligned( vec, tolerance );
1058}
1059
1060inline bool ofVec2f::isAlignedRad( const ofVec2f& vec, float tolerance ) const {
1061 return fabs( this->angleRad( vec ) ) < tolerance;
1062}
1063inline bool ofVec2f::alignRad( const ofVec2f& vec, float tolerance ) const {
1064 return isAlignedRad( vec, tolerance );
1065}
1066
1067
1068// Overloading for any type to any type
1069//
1070//
1071
1072inline ofVec2f ofVec2f::operator+( const ofVec2f& vec ) const {
1073 return ofVec2f( x+vec.x, y+vec.y);
1074}
1075
1076inline ofVec2f& ofVec2f::operator+=( const ofVec2f& vec ) {
1077 x += vec.x;
1078 y += vec.y;
1079 return *this;
1080}
1081
1082inline ofVec2f ofVec2f::operator-( const ofVec2f& vec ) const {
1083 return ofVec2f(x-vec.x, y-vec.y);
1084}
1085
1086inline ofVec2f& ofVec2f::operator-=( const ofVec2f& vec ) {
1087 x -= vec.x;
1088 y -= vec.y;
1089 return *this;
1090}
1091
1092inline ofVec2f ofVec2f::operator*( const ofVec2f& vec ) const {
1093 return ofVec2f(x*vec.x, y*vec.y);
1094}
1095
1096inline ofVec2f& ofVec2f::operator*=( const ofVec2f& vec ) {
1097 x*=vec.x;
1098 y*=vec.y;
1099 return *this;
1100}
1101
1102inline ofVec2f ofVec2f::operator/( const ofVec2f& vec ) const {
1103 return ofVec2f( vec.x!=0 ? x/vec.x : x , vec.y!=0 ? y/vec.y : y);
1104}
1105
1106inline ofVec2f& ofVec2f::operator/=( const ofVec2f& vec ) {
1107 vec.x!=0 ? x/=vec.x : x;
1108 vec.y!=0 ? y/=vec.y : y;
1109 return *this;
1110}
1111
1112inline std::ostream& operator<<(std::ostream& os, const ofVec2f& vec) {
1113 os << vec.x << ", " << vec.y;
1114 return os;
1115}
1116
1117inline std::istream& operator>>(std::istream& is, ofVec2f& vec) {
1118 is >> vec.x;
1119 is.ignore(2);
1120 is >> vec.y;
1121 return is;
1122}
1123
1124//operator overloading for float
1125//
1126//
1127//inline void ofVec2f::operator=( const float f){
1128// x = f;
1129// y = f;
1130//}
1131
1132inline ofVec2f ofVec2f::operator+( const float f ) const {
1133 return ofVec2f( x+f, y+f);
1134}
1135
1136inline ofVec2f& ofVec2f::operator+=( const float f ) {
1137 x += f;
1138 y += f;
1139 return *this;
1140}
1141
1142inline ofVec2f ofVec2f::operator-( const float f ) const {
1143 return ofVec2f( x-f, y-f);
1144}
1145
1146inline ofVec2f& ofVec2f::operator-=( const float f ) {
1147 x -= f;
1148 y -= f;
1149 return *this;
1150}
1151
1152inline ofVec2f ofVec2f::operator-() const {
1153 return ofVec2f(-x, -y);
1154}
1155
1156inline ofVec2f ofVec2f::operator*( const float f ) const {
1157 return ofVec2f(x*f, y*f);
1158}
1159
1160inline ofVec2f& ofVec2f::operator*=( const float f ) {
1161 x*=f;
1162 y*=f;
1163 return *this;
1164}
1165
1166inline ofVec2f ofVec2f::operator/( const float f ) const {
1167 if(f == 0) return ofVec2f(x, y);
1168
1169 return ofVec2f(x/f, y/f);
1170}
1171
1172inline ofVec2f& ofVec2f::operator/=( const float f ) {
1173 if(f == 0) return *this;
1174
1175 x/=f;
1176 y/=f;
1177 return *this;
1178}
1179
1180inline ofVec2f ofVec2f::rescaled( const float length ) const {
1181 return getScaled(length);
1182}
1183
1184inline ofVec2f ofVec2f::getScaled( const float length ) const {
1185 float l = (float)sqrt(x*x + y*y);
1186 if( l > 0 )
1187 return ofVec2f( (x/l)*length, (y/l)*length );
1188 else
1189 return ofVec2f();
1190}
1191
1192inline ofVec2f& ofVec2f::rescale( const float length ){
1193 return scale(length);
1194}
1195
1196inline ofVec2f& ofVec2f::scale( const float length ) {
1197 float l = (float)sqrt(x*x + y*y);
1198 if (l > 0) {
1199 x = (x/l)*length;
1200 y = (y/l)*length;
1201 }
1202 return *this;
1203}
1204
1205
1206
1207// Rotation
1208//
1209//
1210inline ofVec2f ofVec2f::rotated( float angle ) const {
1211 return getRotated(angle);
1212}
1213
1214inline ofVec2f ofVec2f::getRotated( float angle ) const {
1215 float a = (float)(ofDegToRad(angle));
1216 return ofVec2f( x*cos(a) - y*sin(a),
1217 x*sin(a) + y*cos(a) );
1218}
1219
1220inline ofVec2f ofVec2f::getRotatedRad( float angle ) const {
1221 float a = angle;
1222 return ofVec2f( x*cos(a) - y*sin(a),
1223 x*sin(a) + y*cos(a) );
1224}
1225
1226inline ofVec2f& ofVec2f::rotate( float angle ) {
1227 float a = (float)(ofDegToRad(angle));
1228 float xrot = x*cos(a) - y*sin(a);
1229 y = x*sin(a) + y*cos(a);
1230 x = xrot;
1231 return *this;
1232}
1233
1234inline ofVec2f& ofVec2f::rotateRad( float angle ) {
1235 float a = angle;
1236 float xrot = x*cos(a) - y*sin(a);
1237 y = x*sin(a) + y*cos(a);
1238 x = xrot;
1239 return *this;
1240}
1241
1242
1243
1244// Rotate point by angle (deg) around pivot point.
1245//
1246//
1247
1248// This method is deprecated in 006 please use getRotated instead
1249inline ofVec2f ofVec2f::rotated( float angle, const ofVec2f& pivot ) const {
1250 return getRotated(angle, pivot);
1251}
1252
1253inline ofVec2f ofVec2f::getRotated( float angle, const ofVec2f& pivot ) const {
1254 float a = (float)(ofDegToRad(angle));
1255 return ofVec2f( ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x,
1256 ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y );
1257}
1258
1259inline ofVec2f& ofVec2f::rotate( float angle, const ofVec2f& pivot ) {
1260 float a = (float)(ofDegToRad(angle));
1261 float xrot = ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x;
1262 y = ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y;
1263 x = xrot;
1264 return *this;
1265}
1266
1267inline ofVec2f ofVec2f::getRotatedRad( float angle, const ofVec2f& pivot ) const {
1268 float a = angle;
1269 return ofVec2f( ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x,
1270 ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y );
1271}
1272
1273inline ofVec2f& ofVec2f::rotateRad( float angle, const ofVec2f& pivot ) {
1274 float a = angle;
1275 float xrot = ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x;
1276 y = ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y;
1277 x = xrot;
1278 return *this;
1279}
1280
1281
1282
1283// Map point to coordinate system defined by origin, vx, and vy.
1284//
1285//
1286
1287// This method is deprecated in 006 please use getMapped instead
1288inline ofVec2f ofVec2f::mapped( const ofVec2f& origin,
1289 const ofVec2f& vx,
1290 const ofVec2f& vy ) const{
1291 return getMapped(origin, vx, vy);
1292}
1293
1294inline ofVec2f ofVec2f::getMapped( const ofVec2f& origin,
1295 const ofVec2f& vx,
1296 const ofVec2f& vy ) const
1297{
1298 return ofVec2f( origin.x + x*vx.x + y*vy.x,
1299 origin.y + x*vx.y + y*vy.y );
1300}
1301
1302inline ofVec2f& ofVec2f::map( const ofVec2f& origin,
1303 const ofVec2f& vx, const ofVec2f& vy )
1304{
1305 float xmap = origin.x + x*vx.x + y*vy.x;
1306 y = origin.y + x*vx.y + y*vy.y;
1307 x = xmap;
1308 return *this;
1309}
1310
1311
1312// Distance between two points.
1313//
1314//
1315inline float ofVec2f::distance( const ofVec2f& pnt) const {
1316 float vx = x-pnt.x;
1317 float vy = y-pnt.y;
1318 return (float)sqrt(vx*vx + vy*vy);
1319}
1320
1321//this method is deprecated in 006 please use squareDistance
1322inline float ofVec2f::distanceSquared( const ofVec2f& pnt ) const {
1323 return squareDistance(pnt);
1324}
1325
1326inline float ofVec2f::squareDistance( const ofVec2f& pnt ) const {
1327 float vx = x-pnt.x;
1328 float vy = y-pnt.y;
1329 return vx*vx + vy*vy;
1330}
1331
1332
1333
1334// Linear interpolation.
1335//
1336//
1337//
1338// p==0.0 results in this point, p==0.5 results in the
1339// midpoint, and p==1.0 results in pnt being returned.
1340//
1341
1342// this method is deprecated in 006 please use getInterpolated
1343inline ofVec2f ofVec2f::interpolated( const ofVec2f& pnt, float p ) const{
1344 return getInterpolated(pnt, p);
1345}
1346
1347inline ofVec2f ofVec2f::getInterpolated( const ofVec2f& pnt, float p ) const {
1348 return ofVec2f( x*(1-p) + pnt.x*p, y*(1-p) + pnt.y*p );
1349}
1350
1351inline ofVec2f& ofVec2f::interpolate( const ofVec2f& pnt, float p ) {
1352 x = x*(1-p) + pnt.x*p;
1353 y = y*(1-p) + pnt.y*p;
1354 return *this;
1355}
1356
1357// this method is deprecated in 006 please use getMiddle
1358inline ofVec2f ofVec2f::middled( const ofVec2f& pnt ) const{
1359 return getMiddle(pnt);
1360}
1361
1362inline ofVec2f ofVec2f::getMiddle( const ofVec2f& pnt ) const {
1363 return ofVec2f( (x+pnt.x)/2.0f, (y+pnt.y)/2.0f );
1364}
1365
1366inline ofVec2f& ofVec2f::middle( const ofVec2f& pnt ) {
1367 x = (x+pnt.x)/2.0f;
1368 y = (y+pnt.y)/2.0f;
1369 return *this;
1370}
1371
1372
1373
1374
1375
1376inline ofVec2f& ofVec2f::average( const ofVec2f* points, std::size_t num ) {
1377 if (0 == num) {
1378 return *this;
1379 }
1380 x = 0.f;
1381 y = 0.f;
1382 for( std::size_t i=0; i<num; i++) {
1383 x += points[i].x;
1384 y += points[i].y;
1385 }
1386 x /= num;
1387 y /= num;
1388 return *this;
1389}
1390
1391
1392
1393// Normalization
1394//
1395//
1396inline ofVec2f ofVec2f::normalized() const {
1397 return getNormalized();
1398}
1399
1400inline ofVec2f ofVec2f::getNormalized() const {
1401 float length = (float)sqrt(x*x + y*y);
1402 if( length > 0 ) {
1403 return ofVec2f( x/length, y/length );
1404 } else {
1405 return ofVec2f();
1406 }
1407}
1408
1409inline ofVec2f& ofVec2f::normalize() {
1410 float length = (float)sqrt(x*x + y*y);
1411 if( length > 0 ) {
1412 x /= length;
1413 y /= length;
1414 }
1415 return *this;
1416}
1417
1418
1419
1420// Limit length.
1421//
1422//
1423inline ofVec2f ofVec2f::limited(float max) const{
1424 return getLimited(max);
1425}
1426
1427inline ofVec2f ofVec2f::getLimited(float max) const {
1428 ofVec2f limited;
1429 float lengthSquared = (x*x + y*y);
1430 if( lengthSquared > max*max && lengthSquared > 0 ) {
1431 float ratio = max/(float)sqrt(lengthSquared);
1432 limited.set( x*ratio, y*ratio);
1433 } else {
1434 limited.set(x,y);
1435 }
1436 return limited;
1437}
1438
1439inline ofVec2f& ofVec2f::limit(float max) {
1440 float lengthSquared = (x*x + y*y);
1441 if( lengthSquared > max*max && lengthSquared > 0 ) {
1442 float ratio = max/(float)sqrt(lengthSquared);
1443 x *= ratio;
1444 y *= ratio;
1445 }
1446 return *this;
1447}
1448
1449
1450
1451// Perpendicular normalized vector.
1452//
1453//
1454inline ofVec2f ofVec2f::perpendiculared() const {
1455 return getPerpendicular();
1456}
1457
1458inline ofVec2f ofVec2f::getPerpendicular() const {
1459 float length = (float)sqrt( x*x + y*y );
1460 if( length > 0 )
1461 return ofVec2f( -(y/length), x/length );
1462 else
1463 return ofVec2f();
1464}
1465
1467 float length = (float)sqrt( x*x + y*y );
1468 if( length > 0 ) {
1469 float _x = x;
1470 x = -(y/length);
1471 y = _x/length;
1472 }
1473 return *this;
1474}
1475
1476
1477// Length
1478//
1479//
1480inline float ofVec2f::length() const {
1481 return (float)sqrt( x*x + y*y );
1482}
1483
1484inline float ofVec2f::lengthSquared() const {
1485 return (float)(x*x + y*y);
1486}
1487
1488
1489inline float ofVec2f::angle( const ofVec2f& vec ) const {
1490 return ofRadToDeg(atan2( x*vec.y-y*vec.x, x*vec.x + y*vec.y ));
1491}
1492
1493inline float ofVec2f::angleRad( const ofVec2f& vec ) const {
1494 return atan2( x*vec.y-y*vec.x, x*vec.x + y*vec.y );
1495}
1496
1497
1498inline float ofVec2f::dot( const ofVec2f& vec ) const {
1499 return x*vec.x + y*vec.y;
1500}
1501
1502
1503
1504
1505
1506
1507
1508// Non-Member operators
1509//
1510//
1511inline ofVec2f operator+( float f, const ofVec2f& vec ) {
1512 return ofVec2f( f+vec.x, f+vec.y);
1513}
1514
1515inline ofVec2f operator-( float f, const ofVec2f& vec ) {
1516 return ofVec2f( f-vec.x, f-vec.y);
1517}
1518
1519inline ofVec2f operator*( float f, const ofVec2f& vec ) {
1520 return ofVec2f( f*vec.x, f*vec.y);
1521}
1522
1523inline ofVec2f operator/( float f, const ofVec2f& vec ) {
1524 return ofVec2f( f/vec.x, f/vec.y);
1525}
1526
1527
ofVec2f is a class for storing a two dimensional vector.
Definition ofVec2f.h:72
ofVec2f & operator-=(const ofVec2f &vec)
Super easy subtraction assignment. Subtracts vec.x from x, and subtracts vec.y from y.
const float * getPtr() const
Definition ofVec2f.h:163
float operator[](int n) const
Definition ofVec2f.h:181
ofVec2f & operator+=(const ofVec2f &vec)
Super easy addition assignment. Adds vec.x to x, and adds vec.y to y.
ofVec2f & rotateRad(float angle)
Rotates this vector by 'angle' radians about the origin.
float distance(const ofVec2f &pnt) const
Distance between two points.
ofVec2f & operator*=(const ofVec2f &vec)
Multiplies x by vec.x, and multiplies y by vec.y.
bool align(const ofVec2f &vec, float tolerance=0.0001f) const
Determine if two vectors are aligned.
ofVec2f getNormalized() const
Returns a normalized copy of this vector.
float lengthSquared() const
Return the squared length (squared magnitude) of this vector.
ofVec2f getRotatedRad(float angle) const
Returns a new vector that is the result of rotating this vector by 'angle' radians about the origin.
ofVec2f getRotatedRad(float angle, const ofVec2f &pivot) const
Returns a new vector that is the result of rotating this vector by 'angle' radians about the origin.
ofVec2f(float x, float y)
Construct a 2D vector with specific x and `y components.
ofVec2f operator*(const ofVec2f &vec) const
Returns a new vector (x*vec.x , y*vec.y).
ofVec2f & average(const ofVec2f *points, std::size_t num)
Average vector over an array of points.
ofVec2f & rotate(float angle)
Rotates this vector by 'angle' degrees about the origin.
bool operator==(const ofVec2f &vec) const
Check for equality between two ofVec2f.
ofVec2f & perpendicular()
Set this vector to its own normalized perpendicular (by rotating 90 degrees and normalizing).
float dot(const ofVec2f &vec) const
Returns the dot product of this vector with 'vec'.
ofVec2f()
Construct a 2D vector.
float y
Stores the y component of the vector.
Definition ofVec2f.h:82
ofVec2f operator/(const float f) const
Return a new ofVec2f that is this vector scaled by dividing both x and y members by f.
ofVec2f operator-() const
Returns a new ofVec2f that is the inverted version (mirrored in X and Y) of this vector.
ofVec2f operator+(const float f) const
Returns a new vector with a float value f added to both x and y members.
ofVec2f getMapped(const ofVec2f &origin, const ofVec2f &vx, const ofVec2f &vy) const
Get vector mapped to new coordinate system.
void set(const ofVec2f &vec)
Set the x and y components of this vector by copying the corresponding values from vec.
ofVec2f getPerpendicular() const
Return the normalized ofVec2f that is perpendicular to this vector (ie rotated 90 degrees and normali...
ofVec2f & operator*=(const float f)
Scale this vector by multiplying both x and y members by f.
ofVec2f operator*(const float f) const
Return a new ofVec2f that is this vector scaled by multiplying both x and y members by the float.
ofVec2f getMiddle(const ofVec2f &pnt) const
Calculate and return the midpoint between this vector and pnt.
float x
Stores the x component of the vector.
Definition ofVec2f.h:79
ofVec2f & rotate(float angle, const ofVec2f &pivot)
Rotates this vector by 'angle' degrees about the point 'pivot'.
void set(float x, float y)
Set x and y components of this vector with just one function call.
float * getPtr()
Returns a pointer to the memory position of the first element of the vector (x); the second element (...
Definition ofVec2f.h:159
ofVec2f operator+(const ofVec2f &vec) const
Super easy vector addition. Returns a new vector (x+vec.x,y+vec.y).
bool isAlignedRad(const ofVec2f &vec, float tolerance=0.0001f) const
Determine if two vectors are aligned with tolerance in radians.
ofVec2f & operator/=(const float f)
Scale this vector by dividing both x and y members by f.
ofVec2f & scale(const float length)
Scales this vector up or down so that it has the requested length.
ofVec2f & interpolate(const ofVec2f &pnt, float p)
Linear interpolation.
bool match(const ofVec2f &vec, float tolerance=0.0001f) const
Returns true if each component is close enough to its corresponding component in vec,...
ofVec2f & middle(const ofVec2f &pnt)
Set this vector to the midpoint between itself and pnt.
ofVec2f getInterpolated(const ofVec2f &pnt, float p) const
Linear interpolation.
ofVec2f & operator/=(const ofVec2f &vec)
Divides x by vec.x, and divides y by vec.y.
bool isAligned(const ofVec2f &vec, float tolerance=0.0001f) const
Determine if two vectors are aligned.
bool operator!=(const ofVec2f &vec) const
Check for inequality between two ofVec2f.
bool alignRad(const ofVec2f &vec, float tolerance=0.0001f) const
Determine if two vectors are aligned with tolerance in radians.
ofVec2f getLimited(float max) const
Get vector limited by length.
ofVec2f & operator-=(const float f)
Subtract a float value f from both x and y members.
ofVec2f & rotateRad(float angle, const ofVec2f &pivot)
Rotates this vector by 'angle' radians about the point 'pivot'.
float angle(const ofVec2f &vec) const
Calculate the angle to another vector in degrees.
ofVec2f getRotated(float angle) const
Returns a new vector that is the result of rotating this vector by 'angle' degrees about the origin.
ofVec2f(const glm::vec2 &v)
ofVec2f operator-(const ofVec2f &vec) const
Super easy vector subtraction. Returns a new vector (x-vec.x,y-vec.y).
ofVec2f operator/(const ofVec2f &vec) const
Returns a new vector (x/vec.x,y/vec.y).
ofVec2f getScaled(const float length) const
ofVec2f & limit(float max)
Restrict the length (magnitude) of this vector to a maximum of max units by scaling down if necessary...
ofVec2f & normalize()
Normalize the vector.
ofVec2f operator-(const float f) const
Returns a new vector with a float value f subtracted from both x and y members.
float & operator[](int n)
Allows to access the x and y components of an ofVec2f as though it is an array.
Definition ofVec2f.h:177
ofVec2f & map(const ofVec2f &origin, const ofVec2f &vx, const ofVec2f &vy)
Maps this vector from its default coordinate system – origin (0,0), X direction (1,...
ofVec2f(float scalar)
Construct a 2D vector with x and y set to scalar
void set(float scalar)
float angleRad(const ofVec2f &vec) const
Calculate the angle to another vector in radians.
float squareDistance(const ofVec2f &pnt) const
Distance between two points squared.
ofVec2f & operator+=(const float f)
Adds a float value f to both x and y members.
float length() const
Return the length (magnitude) of this vector.
ofVec2f getRotated(float angle, const ofVec2f &pivot) const
Returns a new vector that is the result of rotating this vector by 'angle' degrees about the point 'p...
ofVec3f is a class for storing a three dimensional vector.
Definition ofVec3f.h:79
Definition ofVec4f.h:11
#define OF_DEPRECATED_MSG(message,...)
Definition ofConstants.h:78
float ofDegToRad(float degrees)
Convert degrees to radians.
Definition ofMath.cpp:142
float ofRadToDeg(float radians)
Convert radians to degrees.
Definition ofMath.cpp:137
std::ostream & operator<<(std::ostream &os, const ofMatrix3x3 &M)
Definition ofMatrix3x3.cpp:304
std::istream & operator>>(std::istream &is, ofMatrix3x3 &M)
Definition ofMatrix3x3.cpp:323
#define a
glm::vec3 operator+(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:292
glm::vec3 operator/(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:307
glm::vec3 operator*(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:302
glm::vec3 operator-(const glm::vec3 &v1, const ofVec3f &v2)
Definition ofVectorMath.h:297