#include "pch.h"
std::vector<techlego::pos2d> read_asc_file(const std::wstring& path)
{
std::ifstream ifs(path);
std::string line;
std::vector<techlego::pos2d>res;
while (std::getline(ifs, line))
{
if (line.empty())
{
continue;
}
float d0{};
float d1{};
float d2{};
float d3{};
float d4{};
float d5{};
sscanf_s(line.data(), "%f %f %f %f %f %f", &d0, &d1, &d2, &d3, &d4, &d5);
res.emplace_back(techlego::pos2d{ d0, d1 });
}
return res;
}
int main()
{
//测试数据路径
std::wstring data_path = L"D:\\soft_product1\\techlego_sdk\\C++\\examples\\拟合2d圆\\data.asc";
//读取测试数据
std::vector<techlego::pos2d> points = read_asc_file(data_path);
double x{}, y{}, r{};
//进行2D圆粗拟合
auto error = techlego::fit_circle_fast(points, x, y, r);
std::cout << "error:" << error << "\n";
std::cout << "x:" << x << "\n";
std::cout << "y:" << y << "\n";
std::cout << "r:" << r << "\n\n";
//根据粗拟合的结果再进行2D圆拟合
error = techlego::fit_cricle_fine(points, x, y, r);
std::cout << "error:" << error << "\n";
std::cout << "x:" << x << "\n";
std::cout << "y:" << y << "\n";
std::cout << "r:" << r << "\n";
return 0;
}