出于文档目的,我想展示可用于描述球体上的位置的各种球面坐标系(即位置可以描述为xyz坐标或翻转方位角,方位角 - 超高或超高方位角等)。
我没有在.net上找到清晰的插图,特别是对于非常规约定,我想使用matlab创建简单的插图,如下面的一个(翻转方位角系统),其中,imao,是直截了当地理解:
无论如何我想知道如何创建弯曲的箭头以显示角度方向(上图中的phi / theta箭头)。使用quiver3绘制直向量是可以的。我尝试阅读stream3
,但没有明白使用情况。我想要一些简单的东西:
function [h] = CreateCurvedArrow(startXYZ, endXYZ)
%[
% Draw curved-line in the plane defined by
% vectors 'Origin->StartXYZ' and 'Origin->EndXYZ'
% going from 'StartXYZ' to 'EndXYZ'
%]
我希望有一些简单的方法可以做到这一点,我会使用线段来处理。
答案 0 :(得分:5)
只是为了乐趣:
算法缓慢地将Center->StartPoint
向量旋转到Center->EndPoint
轴周围的Normal
向量,并使用中间点绘制弯曲箭头。当然可以进一步改进实施:
function [] = TestCurvedArrow()
%[
hold on
CreateCurvedArrow3(0.3*[1 0 0], 0.3*[0 1 0]);
CreateCurvedArrow3(0.2*[0 1 0], 0.2*[0 0 1]);
CreateStraightArrow([0 0 0], [1 0 0], 'r');
CreateStraightArrow([0 0 0], [0 1 0], 'g');
CreateStraightArrow([0 0 0], [0 0 1], 'b');
hold off
daspect([1 1 1]);
%]
end
%% --- Creates a curved arrow
% from: Starting position - (x,y,z) upplet
% to: Final position - (x,y,z) upplet
% center: Center of arc - (x,y,z) upplet => by default the origin
% count: The number of segment to draw the arrow => by default 15
function [h] = CreateCurvedArrow3(from, to, center, count)
%[
% Inputs
if (nargin < 4), count = 15; end
if (nargin < 3), center = [0 0 0]; end
center = center(:); from = from(:); to = to(:);
% Start, stop and normal vectors
start = from - center; rstart = norm(start);
stop = to - center; rstop = norm(stop);
angle = atan2(norm(cross(start,stop)), dot(start,stop));
normal = cross(start, stop); normal = normal / norm(normal);
% Compute intermediate points by rotating 'start' vector
% toward 'end' vector around 'normal' axis
% See: http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/
phiAngles = linspace(0, angle, count);
r = linspace(rstart, rstop, count) / rstart;
intermediates = zeros(3, count);
a = center(1); b = center(2); c = center(3);
u = normal(1); v = normal(2); w = normal(3);
x = from(1); y = from(2); z = from(3);
for ki = 1:count,
phi = phiAngles(ki);
cosp = cos(phi); sinp = sin(phi);
T = [(u^2+(v^2+w^2)*cosp) (u*v*(1-cosp)-w*sinp) (u*w*(1-cosp)+v*sinp) ((a*(v^2+w^2)-u*(b*v+c*w))*(1-cosp)+(b*w-c*v)*sinp); ...
(u*v*(1-cosp)+w*sinp) (v^2+(u^2+w^2)*cosp) (v*w*(1-cosp)-u*sinp) ((b*(u^2+w^2)-v*(a*u+c*w))*(1-cosp)+(c*u-a*w)*sinp); ...
(u*w*(1-cosp)-v*sinp) (v*w*(1-cosp)+u*sinp) (w^2+(u^2+v^2)*cosp) ((c*(u^2+v^2)-w*(a*u+b*v))*(1-cosp)+(a*v-b*u)*sinp); ...
0 0 0 1 ];
intermediate = T * [x;y;z;r(ki)];
intermediates(:,ki) = intermediate(1:3);
end
% Draw the curved line
% Can be improved of course with hggroup etc...
X = intermediates(1,:);
Y = intermediates(2,:);
Z = intermediates(3,:);
tf = ishold;
if (~tf), hold on; end
h = line(X,Y,Z);
quiver3(X(end-1), Y(end-1), Z(end-1), X(end)-X(end-1), Y(end)-Y(end-1), Z(end)-Z(end-1),1);
if (~tf), hold off; end
%]
end
%% --- Creates normal arrow
% from: Starting position - (x,y,z) upplet
% to: Final position - (x,y,z) upplet
% lineSpec: Line specifications
function [h] = CreateStraightArrow(from, to, lineSpec)
%[
h = quiver3(from(1), from(2), from(3), to(1)-from(1), to(2)-from(2), to(3)-from(3), lineSpec);
%]
end