|

楼主 |
发表于 2025-3-13 10:16:42
|
显示全部楼层
double a = 5.0, b = 3.0; // 椭圆长轴 a,短轴 b
double x = 6.0, y = 4.0; // 测试点 (x, y)
// 计算初始 t 值
double t_init = atan2(y * a, x * b);
// 用 Newton 方法优化 t
double t_optimized = NewtonSolveForEllipse(t_init, a, b, x, y);
// 计算最近点
double closest_x = a * cos(t_optimized);
double closest_y = b * sin(t_optimized);
std::cout << "最近点:" << closest_x << ", " << closest_y << std::endl;
|
|