osci-render/Source/shape/CircleArc.cpp

51 wiersze
1.3 KiB
C++
Czysty Zwykły widok Historia

#include "CircleArc.h"
2023-02-05 17:39:02 +00:00
#include <numbers>
#include "Line.h"
CircleArc::CircleArc(double x, double y, double radiusX, double radiusY, double startAngle, double endAngle) : x(x), y(y), radiusX(radiusX), radiusY(radiusY), startAngle(startAngle), endAngle(endAngle) {}
2023-02-05 17:39:02 +00:00
2024-01-07 16:17:20 +00:00
Point CircleArc::nextVector(double drawingProgress) {
2023-02-05 17:39:02 +00:00
// scale between start and end angle in the positive direction
double angle = startAngle + endAngle * drawingProgress;
2024-01-07 16:17:20 +00:00
return Point(
2023-02-05 17:39:02 +00:00
x + radiusX * std::cos(angle),
y + radiusY * std::sin(angle)
);
}
void CircleArc::scale(double x, double y, double z) {
2023-02-05 17:39:02 +00:00
this->x *= x;
this->y *= y;
this->radiusX *= x;
this->radiusY *= y;
}
void CircleArc::translate(double x, double y, double z) {
2023-02-05 17:39:02 +00:00
this->x += x;
this->y += y;
}
double CircleArc::length() {
2023-02-05 17:39:02 +00:00
if (len < 0) {
len = 0;
2023-09-07 21:04:08 +00:00
// TODO: Replace this, it's stupid. Do a real approximation.
int segments = 5;
2024-01-07 16:17:20 +00:00
Point start;
Point end = nextVector(0);
for (int i = 0; i < segments; i++) {
start = end;
end = nextVector((i + 1) / (double) segments);
len += Line::length(start.x, start.y, start.z, end.x, end.y, end.z);
2023-02-05 17:39:02 +00:00
}
}
return len;
}
std::unique_ptr<Shape> CircleArc::clone() {
return std::make_unique<CircleArc>(x, y, radiusX, radiusY, startAngle, endAngle);
2023-02-05 17:39:02 +00:00
}
std::string CircleArc::type() {
2023-02-05 17:39:02 +00:00
return std::string("Arc");
}