当前位置:网站首页>空间三点画圆代码
空间三点画圆代码
2022-07-24 18:18:00 【飞舞哲】
理论参考:
代码实现:
求圆心、半径及方向向量代码
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
end参数方程代码
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'];
end测试代码
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));
技术交流邮箱:[email protected]
边栏推荐
- Shanghai Jiaotong University team used joint deep learning to optimize metabonomics research
- 数组对象方法 常用遍历方法&高阶函数
- Section 10 cache breakdown follow Daewoo redis ------- directory post
- T245982 「KDOI-01」醉花阴
- Inherit, override, overload
- Common methods of number and math classes
- Baidu touch.js
- 移动端实现0.5px的实用方案
- 关于接口的写法 1链式判读 ?. 2方法执行 (finally)一定会执行
- The 5th Digital China Construction summit opened in Fuzhou, Fujian
猜你喜欢

Section 7 Data Dictionary: hash followed by Daewoo redis ------- directory post

T245982 「KDOI-01」醉花阴

第五届数字中国建设峰会在福建福州开幕

剑指 Offer 21. 调整数组顺序使奇数位于偶数前面

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

In depth analysis of the famous Alibaba cloud log4j vulnerability

Win10 super good-looking mouse theme, you also try it

Inherit, override, overload

Wechat applet

Number of times a number appears in an ascending array
随机推荐
0621~ES&Lucene
0612~quartz timer frame
How does win11 enhance the microphone? Win11 enhanced microphone settings
Int8 & int8, have you ever stumbled like this?
Shanghai Jiaotong University team used joint deep learning to optimize metabonomics research
Single cell code analysis - gynecological cancer single cell transcriptome and chromatin accessibility analysis 1
In depth analysis of the famous Alibaba cloud log4j vulnerability
0627~ holiday knowledge summary
new也可以创建对象,为什么需要工厂模式?
1688/ Alibaba searches new product data by keyword API instructions
Pycharm configuring opencv Library
steam API
XSS bypass pose summary
web渗透经验汇总ing
Baidu touch.js
About the writing method of interface 1 chain interpretation 2. Method execution (finally) must be executed
数组扁平化.flat(Infinity)
Flatten array.Flat (infinity)
PXE高效批量网络装机
The drop-down list component uses iscrol JS to achieve the rolling effect of the pit encountered