当前位置:网站首页>Three dimensional coordinate point fitting sphere (MATLAB and C)
Three dimensional coordinate point fitting sphere (MATLAB and C)
2022-06-12 12:40:00 【April 16!】
3D coordinate point reading .csv file ; Fit a ball , Output ball center and radius
% Least square method for fitting
clear all;
close all
clc;
R = 2; % Spherical radius
x0 = 100; % Spheric Center x coordinate
y0 = 1; % Spheric Center y coordinate
z0 = 76; % Spheric Center z coordinate
points = load( '2.csv');
[mm,nn]=size(points);
x=points(:,1);
y=points(:,2);
z=points(:,3);
% % The mean value added is 0 Gaussian distribution noise
% amp = 0.5;
% x = x + amp*rand(mm,1);
% y = y + amp*rand(mm,1);
% z = z + amp*rand(mm,1);
% Spherical fitting algorithm
num_points = mm;
x_avr = sum(x)/num_points;
y_avr = sum(y)/num_points;
z_avr = sum(z)/num_points;
xx_avr = sum(x.*x)/num_points;
yy_avr = sum(y.*y)/num_points;
zz_avr = sum(z.*z)/num_points;
xy_avr = sum(x.*y)/num_points;
xz_avr = sum(x.*z)/num_points;
yz_avr = sum(y.*z)/num_points;
xxx_avr = sum(x.*x.*x)/num_points;
xxy_avr = sum(x.*x.*y)/num_points;
xxz_avr = sum(x.*x.*z)/num_points;
xyy_avr = sum(x.*y.*y)/num_points;
xzz_avr = sum(x.*z.*z)/num_points;
yyy_avr = sum(y.*y.*y)/num_points;
yyz_avr = sum(y.*y.*z)/num_points;
yzz_avr = sum(y.*z.*z)/num_points;
zzz_avr = sum(z.*z.*z)/num_points;
% Calculate the coefficient matrix for solving linear equations
A = [xx_avr - x_avr*x_avr,xy_avr - x_avr*y_avr,xz_avr - x_avr*z_avr;
xy_avr - x_avr*y_avr,yy_avr - y_avr*y_avr,yz_avr - y_avr*z_avr;
xz_avr - x_avr*z_avr,yz_avr - y_avr*z_avr,zz_avr - z_avr*z_avr];
b = [xxx_avr - x_avr*xx_avr + xyy_avr - x_avr*yy_avr + xzz_avr - x_avr*zz_avr;
xxy_avr - y_avr*xx_avr + yyy_avr - y_avr*yy_avr + yzz_avr - y_avr*zz_avr;
xxz_avr - z_avr*xx_avr + yyz_avr - z_avr*yy_avr + zzz_avr - z_avr*zz_avr];
b = b/2;
resoult = A\b
x00 = resoult(1) ; % Fitted x coordinate
y00 = resoult(2); % Fitted y coordinate
z00 = resoult(3) ; % Fitted z coordinate
r = sqrt(xx_avr-2*x00*x_avr+x00*x00 + yy_avr-2*y00*y_avr+y00*y00 + zz_avr-2*z00*z_avr+z00*z00) % The fitted sphere radius r
C Version code : use ransac Algorithm , Enter a series of points , Output radius and Center ; Here is 2 Vader , It can be modified to three-dimensional , Three dimensional center and radius calculation can refer to the algorithm of four points to determine a circle ;
https://github.com/xiapengchng/Ransac-Fit-a-circle
边栏推荐
- Suggestions and skills for advanced version of go language test
- Influxdb2.x benchmark tool - influxdb comparisons
- Dasctf Sept x Zhejiang University of technology autumn challenge Web
- Tuples, arrays, and as const of typescript
- InfluxDB2.x 基准测试工具 - influxdb-comparisons
- itk::Neighborhood获取6邻域、18邻域、26邻域,18/6邻域,26/18邻域
- TRON-api-波场转账查询接口-PHP版本-基于ThinkPHP5封装-附带接口文档-20220602版本-接口部署好适用于任何开发语言
- In depth anatomy of C language - key words & supplementary contents
- 三维坐标点拟合球(matlab and C )
- 【VIM】.vimrc配置,已经安装Vundle,YoucompleteMe
猜你喜欢

NDT registration principle

Introduction and test of MySQL partition table

C语言进阶篇——深度解剖数据在内存中的存储(配练习)
![[JS] some handwriting functions: deep copy, bind, debounce, etc](/img/f8/cf51a24450a88abb9e68c78e0e3aa8.jpg)
[JS] some handwriting functions: deep copy, bind, debounce, etc

Problems encountered in installing canvas and errors encountered in running the project

Geek challenge 2021 Web
![VNCTF2022 [WEB]](/img/36/a70763d74e503ddc888b8fc38f8677.jpg)
VNCTF2022 [WEB]

Promise knowledge

This direction of ordinary function and arrow function

Reasons for college students' leave
随机推荐
Easy to use assistant tools and websites
SEO optimization of web pages
【C语言】关键字static&&多文件&&猜字游戏
A short guide to SSH port forwarding
银行布局元宇宙:数字藏品、数字员工成主赛道!
Soft test network engineer notes
Object. Detailed explanation of assign()
InfluxDB2.x 基准测试工具 - influxdb-comparisons
imx6-uboot添加lvds1显示
Performance comparison test of channel and condition variables of golang in single production and single consumption scenarios
2021-11-16
Congratulations to splashtop for winning the 2022 it Europa "vertical application solution of the year" award
JS pre parsing, object, new keyword
Dasctf Sept x Zhejiang University of technology autumn challenge Web
VGg small convolution instead of large convolution vs deep separable convolution
牛顿法解多项式的根
Tron API wave field transfer query interface PHP version package based on thinkphp5 attached interface document 20220528 version
Influxdb2.x benchmark tool - influxdb comparisons
Dom and BOM in JS
Numpy数值计算基础