当前位置:网站首页>Space three point circle code
Space three point circle code
2022-07-24 18:18:00 【Feiwuzhe】
Code implementation :
Find the center of a circle 、 Radius and direction vector code
function [cp,R,a,b]=CircleFun(p1,p2,p3)
x1=p1(1);y1=p1(2);z1=p1(3);
x2=p2(1);y2=p2(2);z2=p2(3);
x3=p3(1);y3=p3(2);z3=p3(3);
a1 = (y1*z2 - y2*z1 - y1*z3 + y3*z1 + y2*z3 - y3*z2);
b1 = -(x1*z2 - x2*z1 - x1*z3 + x3*z1 + x2*z3 - x3*z2);
c1 = (x1*y2 - x2*y1 - x1*y3 + x3*y1 + x2*y3 - x3*y2);
d1 = -(x1*y2*z3 - x1*y3*z2 - x2*y1*z3 + x2*y3*z1 + x3*y1*z2 - x3*y2*z1);
a2 = 2 * (x2 - x1);
b2 = 2 * (y2 - y1);
c2 = 2 * (z2 - z1);
d2 = x1*x1 + y1*y1 + z1*z1 - x2*x2 - y2*y2 - z2*z2;
a3 = 2 * (x3 - x1);
b3 = 2 * (y3 - y1);
c3 = 2 * (z3 - z1);
d3 = x1*x1 + y1*y1 + z1*z1 - x3*x3 - y3*y3 - z3*z3;
M=[a1 b1 c1 0;
a2 b2 c2 0;
a3 b3 c3 0;
0 0 0 1];
cp=inv(M)*[-d1;-d2;-d3;1];
R=sqrt((x1-cp(1))^2+(y1-cp(2))^2+(z1-cp(3))^2);
n=[a1,b1,c1];
n=n/norm(n);%z-vec
a=[x1-cp(1),y1-cp(2),z1-cp(3)];
a=a/norm(a);%x-vec
b=cross(n,a);%y-vec
endParametric equation code
function xyz=generateCircle(cp,R,a,b,num)
xyz=[];
i=linspace(0,2*pi,num);
x=cp(1) + R*cos(i)*a(1) +R*sin(i)*b(1);
y=cp(2) + R*cos(i)*a(2) +R*sin(i)*b(2);
z=cp(3) + R*cos(i)*a(3) +R*sin(i)*b(3);
xyz=[x',y',z'];
endTest code
clc;
clear all;
close all;
p1=[1,0.5,2]+2*rand(1,3);
p2=[3,-2,4]+3*rand(1,3);
p3=[0,-1.1,2.2]+1.6*rand(1,3);
[cp,R,a,b]=CircleFun(p1,p2,p3);
% [cp1,R1,a1,b1]=CircleFun1(p1,p2,p3);
xyz=generateCircle(cp,R,a,b,100);
figure();
p=[p1;p2;p3];
plot3(p(:,1),p(:,2),p(:,3),'ro');hold on;
plot3(xyz(:,1),xyz(:,2),xyz(:,3));
Technical exchange mailbox :[email protected]
边栏推荐
- Ship new idea 2022.2 was officially released, and the new features are really fragrant!
- 安装JumpServer
- A practical scheme of realizing 0.5px on mobile terminal
- Pytorch的旅程一:线性模型
- JMeter -- silent operation
- 2022 the latest short video de watermarking analysis API interface sharing
- 关于接口的写法 1链式判读 ?. 2方法执行 (finally)一定会执行
- redis集群的三种方式
- The 5th Digital China Construction summit opened in Fuzhou, Fujian
- 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
猜你喜欢

["code" power is fully open, and "chapter" shows strength] list of contributors to the task challenge in the first quarter of 2022

Emerging potential of interactive virtual reality technology in drug discovery

如何用WebGPU流畅渲染百万级2D物体?

【“码”力全开,“章”显实力】2022年第1季Task挑战赛贡献者榜单

Icml2022 Best Paper Award: learning protein reverse folding from millions of predicted structures

05mysql lock analysis

Maximum sum and promotion of continuous subarrays (2)

Handwritten blog platform ~ the next day

pycharm配置opencv库

Wechat applet
随机推荐
steam API
PXE efficient batch network installation
【校验】只能输入数字(正负数)
Common methods of number and math classes
0701~放假总结
手写博客平台~第二天
undefined reference to H5PTopen
How to prepare for hyperinflation
Number of times a number appears in an ascending array
0614~ holiday self study
Blackmagic Fusion Studio 18
A practical scheme of realizing 0.5px on mobile terminal
6126. 设计食物评分系统
How to read "STL source code analysis"?
Maximum sum and promotion of continuous subarrays (2)
Pytorch的旅程一:线性模型
Wu Enda writes: how to establish projects to adapt to AI career
Introduction and use of Pinia
Variable and immutable data types
数组常用方法(2)