-
Notifications
You must be signed in to change notification settings - Fork 2
/
Segment.h
37 lines (29 loc) · 876 Bytes
/
Segment.h
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
34
35
36
37
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#ifndef PHYSICSFORMULA_SEGMENT_H
#define PHYSICSFORMULA_SEGMENT_H
#include "Point.h"
namespace rez {
struct Segment {
Point3d& p1;
Point3d& p2;
};
struct Segment2d {
Point2d p1 = DEFAULT_POINT_2D;
Point2d p2 = DEFAULT_POINT_2D;
Segment2d() {}
//Segment2d(Point2d _p1, Point2d _p2) : p1(_p1), p2(_p2) {}
Segment2d(Point2d& _p1, Point2d& _p2) : p1(_p1), p2(_p2) {}
[[nodiscard]] double get_x(double y) const
{
double x1 = p1[X_];
double y1 = p1[Y_];
double x2 = p2[X_];
double y2 = p2[Y_];
double y2_y1 = y2 - y1;
return y * (x2 - x1) / y2_y1 + (y2 * x1 - y1 * x2) / y2_y1;
}
};
}
#endif //PHYSICSFORMULA_SEGMENT_H