add arc and alt

This commit is contained in:
2026-08-07 16:36:56 +02:00
parent 95225a5811
commit 66bdf9327a
5 changed files with 91 additions and 22 deletions
+43
View File
@@ -25,6 +25,7 @@
#include <iostream>
#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>
#include <numbers>
#include <tuple>
struct sdl_session {
@@ -221,6 +222,48 @@ void line(const uint16_t x1, const uint16_t y1, const uint16_t x2,
0xff);
SDL_RenderLine(main_sdl_session.renderer, x1, y1, x2, y2);
}
#ifdef CONFIG_VECTOR_FOLLOW_TRACK_RATE
void arc(uint16_t start_x, uint16_t start_y, float start_angle_rad, float speed /*in pps*/,float angular_speed_rads, uint16_t duration, color_t color) {
SDL_SetRenderDrawColor(main_sdl_session.renderer, color.r, color.g, color.b,
0xff);
constexpr float DEG2RAD = std::numbers::pi / 180.0f;
// Handle straight line case
if (std::fabs(angular_speed_rads) < 1e-6f) {
uint16_t steps = static_cast<int>(speed * duration);
for (uint16_t i = 0; i <= steps; ++i) {
float t = i / speed;
float x = start_x + std::cos(start_angle_rad) * speed * t;
float y = start_y + std::sin(start_angle_rad) * speed * t;
SDL_RenderPoint(main_sdl_session.renderer,static_cast<int>(std::round(x)), static_cast<int>(std::round(y)));
}
return;
}
float r = speed / angular_speed_rads;
// Center of circle: perpendicular to heading
float center_x = start_x - r * std::sin(start_angle_rad);
float center_y = start_y + r * std::cos(start_angle_rad);
// Angle from center to start point
float radius_angle = std::atan2(start_y - center_y, start_x - center_x);
// Step size in time — approx 1 pixel arc-length per step
float dt = 1.0f / std::max(std::fabs(speed), 1.0f);
uint16_t steps = static_cast<int>(duration / dt);
for (uint16_t i = 0; i <= steps; ++i) {
float t = i * dt;
float a = radius_angle + angular_speed_rads * t;
float x = center_x + std::fabs(r) * std::cos(a);
float y = center_y + std::fabs(r) * std::sin(a);
SDL_RenderPoint(main_sdl_session.renderer,static_cast<int>(std::round(x)), static_cast<int>(std::round(y)));
}
}
#endif
} // namespace draw
namespace net {