RIT VEXU Core API
Loading...
Searching...
No Matches
geometry.h
1
#pragma once
2
#include <cmath>
3
7
struct
point_t
{
8
double
x
;
9
double
y
;
10
16
double
dist
(
const
point_t
other)
const
{
17
return
std::sqrt(std::pow(this->x - other.
x
, 2) + pow(this->y - other.
y
, 2));
18
}
19
25
point_t
operator+
(
const
point_t
&other)
const
{
26
point_t
p{.
x
= this->x + other.
x
, .y = this->y + other.
y
};
27
return
p;
28
}
29
35
point_t
operator-
(
const
point_t
&other)
const
{
36
point_t
p{.
x
= this->x - other.
x
, .y = this->y - other.
y
};
37
return
p;
38
}
39
40
point_t
operator*(
double
s)
const
{
return
{
x
* s,
y
* s}; }
41
point_t
operator/(
double
s)
const
{
return
{
x
/ s,
y
/ s}; }
42
43
point_t
operator-
()
const
{
return
{-
x
, -
y
}; }
44
point_t
operator+
()
const
{
return
{
x
,
y
}; }
45
46
bool
operator==(
const
point_t
&rhs) {
return
x
== rhs.
x
&&
y
== rhs.
y
; }
47
};
48
52
struct
pose_t
{
53
double
x
;
54
double
y
;
55
double
rot
;
56
57
point_t
get_point() {
return
point_t
{.
x
=
x
, .y =
y
}; }
58
};
59
60
struct
Rect {
61
point_t
min;
62
point_t
max;
63
static
Rect from_min_and_size(
point_t
min,
point_t
size) {
return
{min, min + size}; }
64
point_t
dimensions()
const
{
return
max - min; }
65
point_t
center()
const
{
return
(min + max) / 2; }
66
double
width()
const
{
return
max.
x
- min.
x
; }
67
double
height()
const
{
return
max.
y
- min.
y
; }
68
bool
contains(
point_t
p)
const
{
69
bool
xin = p.
x
> min.
x
&& p.
x
< max.
x
;
70
bool
yin = p.
y
> min.
y
&& p.
y
< max.
y
;
71
return
xin && yin;
72
}
73
};
74
75
struct
Mat2 {
76
double
X11, X12;
77
double
X21, X22;
78
point_t
operator*(
const
point_t
p)
const
{
79
double
outx = p.
x
* X11 + p.
y
* X12;
80
double
outy = p.
x
* X21 + p.
y
* X22;
81
return
{outx, outy};
82
}
83
84
static
Mat2 FromRotationDegrees(
double
degrees) {
85
double
rad = degrees * (M_PI / 180.0);
86
double
c = cos(rad);
87
double
s = sin(rad);
88
return
{c, -s, s, c};
89
}
90
};
point_t
Definition
geometry.h:7
point_t::operator+
point_t operator+(const point_t &other) const
Definition
geometry.h:25
point_t::y
double y
the y position in space
Definition
geometry.h:9
point_t::operator-
point_t operator-(const point_t &other) const
Definition
geometry.h:35
point_t::x
double x
the x position in space
Definition
geometry.h:8
point_t::dist
double dist(const point_t other) const
Definition
geometry.h:16
pose_t
Definition
geometry.h:52
pose_t::x
double x
x position in the world
Definition
geometry.h:53
pose_t::y
double y
y position in the world
Definition
geometry.h:54
pose_t::rot
double rot
rotation in the world
Definition
geometry.h:55
include
utils
geometry.h
Generated by
1.10.0