当前位置:网站首页>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
边栏推荐
- Dasctf Sept x Zhejiang University of technology autumn challenge Web
- 恭喜Splashtop 荣获2022年 IT Europa “年度垂直应用解决方案”奖
- Reasons for college students' leave
- This direction of ordinary function and arrow function
- Lightweight ---project
- Attack and defense world re (New 1 hand zone) questions 1-12
- 数组——双指针技巧秒杀七道数组题目
- [JS] some handwriting functions: deep copy, bind, debounce, etc
- Invalid date of moment conversion timestamp
- Numpy numerical calculation basis
猜你喜欢

什么时候运用二分搜索

安全KNN

The 4th Zhejiang CTF preliminary contest web pppop

Examples of Cartesian product and natural connection of relational algebra

【C语言】关键字static&&多文件&&猜字游戏

从基础到源码统统帮你搞定,技术详细介绍

Dasctf Sept x Zhejiang University of technology autumn challenge Web

Numpy数值计算基础

关于派文的问题

vant 标签栏+上拉加载+下拉刷新demo van-tabs+van-pull-refresh+van-list demo
随机推荐
Iterator, generator generator details
Cocktail sort
银行布局元宇宙:数字藏品、数字员工成主赛道!
Part of the fourth Zhejiang CTF finals
二叉树(构造篇)
Introduction, installation and use of core JS
Take the web page animation effects that can be used. Don't you come and have a look?
itk neighbhood
数组——二维数组的花式遍历技巧
【C语言】关键字static&&多文件&&猜字游戏
Point cloud registration -- GICP principle and its application in PCL
C语言进阶篇——万字详解指针和qsort函数
Geek challenge 2021 Web
[an Xun cup 2019]iamthinking
Brush questions [de1ctf 2019]shellshellshell
Deep analysis of advanced pointer -- advanced chapter of C language
Summary of knowledge points of ES6, ES7, es8, es9, ES10, es11 and ES12 (interview)
ITK 多阶段配准
From simple to deep - websocket
VNCTF2022 [WEB]