当前位置:网站首页>Matlab simulation of drawing circle on sphere
Matlab simulation of drawing circle on sphere
2022-07-24 18:18:00 【Feiwuzhe】
Derivation description
For the convenience of formula derivation , In this paper, only when the spherical center is at the origin of coordinates , It should be noted that when the ball center is not at the origin , Just subtract the coordinates of the spherical center from the coordinates of the known conditions , After the solution is completed, add the spherical center coordinates !
deduction :
in front Blog , The code of three point circle drawing has been given , The observation function generateCircle You know , To draw a circle , We only need to know the center of the circle , The plane of the circle x Direction vector and y The direction of the vector .
Next , We focus our work on the above three quantities , Suppose the ball is a unit ball whose center is at the origin of coordinates R=1, We need to be on the ball rs=[0.75,-0.17,0.64] Draw a 15° The circle of , be
It is known that , The radius of the circle is : r=R*sin(15/180*pi);
The direction vector of the plane where the circle is located is :cc=rs=[0.75,-0.17,0.64]
that , The plane equation passing through the origin and parallel to the plane of the circle is :rs(1)*x+rs(2)*y+rs(3)*z=0
that , Take any vector in this plane as x The direction vector of the axis , Such as :nx=[1,1,-(rs(1)+rs(2))/rs(3)]
that , According to the cross product rule ,y The direction vector of the axis is :ny=cross(rs,nx);
Besides , We know , The position of the center of the circle is rs On the straight line connecting with the center of the circle , According to the parameter equation of the ball , The spherical radius of the center of the circle is :rr=R*cos(15/180*pi)
Code for drawing sphere :
function drawsphere(a,b,c,R)
%% Draw sphere
% With (a,b,c) For the center of the ball ,R As the radius of
% Generate the data
[x,y,z] = sphere(20);
% Adjust the radius
x = R*x;
y = R*y;
z = R*z;
% Adjust the ball center
x = x+a;
y = y+b;
z = z+c;
% Use mesh draw
% figure;
% axis equal;
mesh(x,y,z);
% Use surf draw
% figure;
% axis equal;
% surf(x,y,z);
endGenerate the code of points on the circle
%% Generate points on the circle
% cp center of a circle ,R Circle radius ,a Circular plane x Axis direction vector ,b Circular plane y Axis direction vector ,num Number of interpolation points
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
Transformation from rectangular coordinates to spherical coordinates
function xyz=sp2dikaer(azimuth,elevation,r)
x = r .* cos(elevation) .* cos(azimuth);
y = r .* cos(elevation) .* sin(azimuth);
z = r .* sin(elevation);
xyz=[x,y,z];
endReference from matlab Official website
Test code :
clc;clear all;close all;
rs=[0.75,-0.17,0.64];
a=0;
b=0;
c=0;
R=1;
flag=0;
drawsphere(a,b,c,R);
hold on;
plot3(rs(1),rs(2),rs(3),'rp');
%% The radius of the circle
r=R*sin(15/180*pi);
th=0:0.01:2*pi;
azimuth=atan2(rs(2),rs(1));
elevation=atan2(rs(3),sqrt(rs(2)^2+rs(1)^1));
% xyz=sp2dikaer(azimuth,elevation,R)
nx=[1,1,-(rs(1)+rs(2))/rs(3)];
ny=cross(rs,nx);
nx=nx/norm(nx);
ny=ny/norm(ny);
rs1=sp2dikaer(atan2(rs(2),rs(1)),atan2(rs(3),sqrt(sum(rs(1:2).^2))),R*cos(15/180*pi));
xyz=generateCircle(rs1,r,nx,ny,100);
plot3(xyz(:,1),xyz(:,2),xyz(:,3),'r', 'LineWidth',2);
Feiwu zhe technology exchange mailbox :[email protected]
边栏推荐
- 2022 the latest short video de watermarking analysis API interface sharing
- Flink operation Hudi data table
- Problems needing attention in writing pages
- 0623~ holiday self study
- Pytorch的旅程二:梯度下降
- Wechat applet
- 6126. Design food scoring system
- Go language interface and type
- [OBS] dependency Library: x264 vs Build
- Bib | mol2context vec: context aware deep network model learning molecular representation for drug discovery
猜你喜欢

web渗透经验汇总ing

The 5th Digital China Construction summit opened in Fuzhou, Fujian

The drop-down list component uses iscrol JS to achieve the rolling effect of the pit encountered

Laravel笔记-用户登录时密码进行RSA加密(提高系统安全性)

How to render millions of 2D objects smoothly with webgpu?

jmeter --静默运行

Use of jumpserver

How does win11 enhance the microphone? Win11 enhanced microphone settings

05mysql lock analysis

Inheritance and Derive
随机推荐
ES6 cycle filter value
jmeter -- prometheus+grafana服务器性能可视化
数组扁平化.flat(Infinity)
[OBS] cooperation between video and audio coding and RTMP transmission
【刷题记录】20. 有效的括号
Go to bed capacity exchange
pinia 入门及使用
How to read "STL source code analysis"?
Model saving and loading of sklearn
Growth of operation and maintenance Xiaobai - week 8 of Architecture
0621~ES&Lucene
Is header file required? Follow the compilation process~~~
Laravel notes - RSA encryption of user login password (improve system security)
Shanghai Jiaotong University team used joint deep learning to optimize metabonomics research
How to prepare for hyperinflation
数组对象方法 常用遍历方法&高阶函数
0615~用自定义注解实现RBAC权限管理
Common methods of string (2)
Cookies and session "suggestions collection"
6126. Design food scoring system