forked from arturzxc/myapex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Math.cpp
33 lines (29 loc) · 903 Bytes
/
Math.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include <math.h>
namespace math
{
double distanceToMeters(float distance)
{
const float INCHES_TO_METER_RATE = 39.3701;
return distance / INCHES_TO_METER_RATE;
}
double calculateDistance(float x1, float y1, float z1, float x2, float y2, float z2)
{
float dx = (x1 - x2);
float dy = (y1 - y2);
float dz = (z1 - z2);
float distance = sqrt(pow(dx, 2) + pow(dy, 2) + pow(dz, 2));
return distance;
}
double calculateDistanceInMeters(float x1, float y1, float z1, float x2, float y2, float z2)
{
return distanceToMeters(calculateDistance(x1, y1, z1, x2, y2, z2));
}
double calculateDistance2D(float x1, float y1, float x2, float y2)
{
float dx = (x1 - x2);
float dy = (y1 - y2);
float distance = sqrt(pow(dx, 2) + pow(dy, 2));
return distance;
}
}