当前位置:网站首页>三维坐标点拟合球(matlab and C )
三维坐标点拟合球(matlab and C )
2022-06-12 12:27:00 【4月16!】
三维坐标点读取.csv文件;拟合一个球,输出球中心和半径
%最小二乘的方法进行拟合
clear all;
close all
clc;
R = 2; %球面半径
x0 = 100; %球心x坐标
y0 = 1; %球心y坐标
z0 = 76; %球心z坐标
points = load( '2.csv');
[mm,nn]=size(points);
x=points(:,1);
y=points(:,2);
z=points(:,3);
% % 加入均值为0的高斯分布噪声
% amp = 0.5;
% x = x + amp*rand(mm,1);
% y = y + amp*rand(mm,1);
% z = z + amp*rand(mm,1);
%球面拟合算法
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;
%计算求解线性方程的系数矩阵
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) ; %拟合出的x坐标
y00 = resoult(2); %拟合出的y坐标
z00 = resoult(3) ; %拟合出的z坐标
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) %拟合出的球半径r
C版本代码:用ransac算法,输入一系列点,输出半径和圆心;下面是2维得,可以修改为三维的,三维的圆心与半径计算可以参考四点确定一个圆的算法;
https://github.com/xiapengchng/Ransac-Fit-a-circle
边栏推荐
- ELK搭建指南
- Reasons for college students' leave
- [译] Go语言测试进阶版建议与技巧
- [translation] go references - the go memory model | memory model for Chinese translation of official golang documents
- 【数据库】navicat --oracle数据库创建
- C语言深度解剖篇——关键字&&补充内容
- 拿来就能用的网页动画特效,不来看看?
- MySQL review
- For in and object The difference between keys()
- [JS] some handwriting functions: deep copy, bind, debounce, etc
猜你喜欢

Introduction and test of MySQL partition table

WebStorage

VS2019 设置 CTRL+/ 为注释和取消注释快捷键

Common debugging tools and commands for ROS

关系代数笛卡尔积和自然连接的例子

Advanced C language -- storage of deep anatomical data in memory (with exercise)

Left and right cases + rotating pictures of small dots + no time

This direction of ordinary function and arrow function

MySQL 分区表介绍与测试

InfluxDB2.x 基准测试工具 - influxdb-comparisons
随机推荐
AutoLock 解决加锁后忘记解锁问题
Implementation principle of kotlin extension function
【Leetcode】637. Layer average of binary tree
Downloading and using SWI Prolog
Vim,Gcc,Gdb
Shielding does not display vs warning
Traditional DOM rendering?
Advanced C language -- storage of deep anatomical data in memory (with exercise)
JS how to convert a string into an array object
Async/await for ES6
Introduction and test of MySQL partition table
Problems encountered in generating MP3 from text to speech through iFLYTEK voice API
The advantages of saving pointers when saving objects with vector and the use of reserve
[译] QUIC Wire Layout Specification - Packet Types and Formats | QUIC协议标准中文翻译(2) 包类型和格式
Differences between server-side rendering and client-side rendering (advantages and disadvantages)
爱可可AI前沿推介(6.12)
Conversion between ROS map picture pixels and map coordinate system coordinates
银行布局元宇宙:数字藏品、数字员工成主赛道!
vtk 图像序列鼠标交互翻页
WebStorage