Matlab-开普勒轨道上卫星的标绘速度矢量

时间:2019-01-20 19:55:06

标签: matlab vector orbital-mechanics

我必须绘制一个围绕中心物体运行的物体的速度矢量。这是开普勒语境。根据经典公式(r = p /(1 + e * cos(theta)),e =偏心率,推导出物体的轨迹。

我设法绘制椭圆形轨道,但是现在,我想绘制该轨道的每个点的物体速度。

要计算速度矢量,我从2个分量下面的经典公式(到极坐标)开始:

v_r = dr / dt和v_theta = r d(theta)/ dt

要采取时间步dt,我提取与时间成比例的平均异常。

最后,我计算该速度向量的归一化。

clear             % clear variables

e = 0.8;    % eccentricity
a = 5;             % semi-major axis
b = a*sqrt(1-e^2); % semi-minor axis
P = 10             % Orbital period
N = 200;           % number of points defining orbit

nTerms = 10;    % number of terms to keep in infinite series defining
                % eccentric anomaly

M = linspace(0,2*pi,N);   % mean anomaly parameterizes time
                          % M varies from 0 to 2*pi over one orbit

alpha = zeros(1,N);       % preallocate space for eccentric anomaly array



%%%%%%%%%%
%%%%%%%%%%  Calculations & Plotting
%%%%%%%%%%


% Calculate eccentric anomaly at each point in orbit
for j = 1:N
    % initialize eccentric anomaly to mean anomaly
    alpha(j) = M(j);

    % include first nTerms in infinite series
    for n = 1:nTerms
        alpha(j) = alpha(j) + 2 / n * besselj(n,n*e) .* sin(n*M(j));
    end
end

% calcualte polar coordiantes (theta, r) from eccentric anomaly
theta = 2 * atan(sqrt((1+e)/(1-e)) * tan(alpha/2));
r = a * (1-e^2) ./ (1 + e*cos(theta));

% Compute cartesian coordinates with x shifted since focus
x = a*e + r.*cos(theta);
y = r.*sin(theta);
figure(1);
plot(x,y,'b-','LineWidth',2)
xlim([-1.2*a,1.2*a]);
ylim([-1.2*a,1.2*a]);
hold on;
% Plot 2 focus = foci
plot(a*e,0,'ro','MarkerSize',10,'MarkerFaceColor','r');
hold on;
plot(-a*e,0,'ro','MarkerSize',10,'MarkerFaceColor','r');

% compute velocity vectors
for i = 1:N-1
  vr(i) = (r(i+1)-r(i))/(P*(M(i+1)-M(i))/(2*pi));
  vtheta(i) = r(i)*(theta(i+1)-theta(i))/(P*(M(i+1)-M(i))/(2*pi));
  vrNorm(i) = vr(i)/norm([vr(i),vtheta(i)],1);
  vthetaNorm(i) = vtheta(i)/norm([vr(i),vtheta(i)],1);
end 

% Plot velocity vector
quiver(x(30),y(30),vrNorm(30),vthetaNorm(30),'LineWidth',2,'MaxHeadSize',1);

% Label plot with eccentricity
title(['Elliptical Orbit with e = ' sprintf('%.2f',e)]);

不幸的是,一旦执行绘图,看来我得到了速度方面的错误矢量。例如,以30thvrNorm数组的vthetaNorm元素为例: bad direction

如您所见,向量的方向是错误的(如果我假设右轴的theta取0,并且像三角学一样取正变化)。

如果有人可以看到我的错误在哪里,那会很好。

更新1:该矢量是否表示椭圆轨道上的速度与椭圆曲线永久相切?

我想以正确的焦点为出发点来表示它。

更新2:

通过@MadPhysicist的解决方案,我进行了修改:

% compute velocity vectors
  vr(1:N-1) = (2*pi).*diff(r)./(P.*diff(M));
  vtheta(1:N-1) = (2*pi).*r(1:N-1).*diff(theta)./(P.*diff(M));

  % Plot velocity vector
  for l = 1:9    quiver(x(20*l),y(20*l),vr(20*l)*cos(vtheta(20*l)),vr(20*l)*sin(vtheta(20*l)),'LineWidth',2,'MaxHeadSize',1);
  end
  % Label plot with eccentricity
  title(['Elliptical Orbit with e = ' sprintf('%.2f',e)]);

我得到以下结果:

enter image description here

在轨道的某些部分,我得到了错误的方向,而且我不明白为什么...

1 个答案:

答案 0 :(得分:0)

您的代码有两个问题:

  1. 归一化处理不正确。 norm计算向量的广义p范数,该向量默认为欧几里得范数。它期望笛卡尔输入。将p设置为1意味着它只会返回向量的最大元素。在您的情况下,规范化是没有意义的。只需将vrNorm设置为

    vrNorm = vr ./ max(vr)
    
  2. 似乎您正在将极坐标vrNormvthetaNorm传递到quiver,这需要笛卡尔坐标。以向量化的方式进行转换很容易:

    vxNorm = vrNorm * cos(vtheta);
    vyNorm = vrNorm * sin(vtheta);
    

这假设我了解您的角度正确来自哪里,并且vtheta以弧度为单位。

注意

整个循环

for i = 1:N-1
    vr(i) = (r(i+1)-r(i))/(P*(M(i+1)-M(i))/(2*pi));
    vtheta(i) = r(i)*(theta(i+1)-theta(i))/(P*(M(i+1)-M(i))/(2*pi));
    vrNorm(i) = vr(i)/norm([vr(i),vtheta(i)],1);
    vthetaNorm(i) = vtheta(i)/norm([vr(i),vtheta(i)],1);
end

可以完全矢量化的方式重写:

vr = (2 * pi) .* diff(r) ./ (P .* diff(M))
vtheta = (2 * pi) .* r .* diff(theta) ./ (P .* diff(M))
vrNorm = vr ./ max(vr)
vxNorm = vrNorm * cos(vtheta);
vyNorm = vrNorm * sin(vtheta);

注释2

您可以在整个数据集或子集上以矢量化方式调用quiver

quiver(x(20:199:20), y(20:199:20), vxNorm(20:199:20), vyNorm(20:199:20), ...)