
Table of Contents
- Background
- Results
- Modeling
- Calculation
- MATLAB Code
Background
This MATLAB program simulates the determination of the spacecraft’s position with noise when receiving the positions of two near objects and three stars. Reference textbook: “Principles and Methods of Autonomous Astronomical Navigation for Spacecraft”, National Defense Industry Press, 2nd Edition, by Fang Jiancheng et al..
- Near Objects: Earth and Moon, or Sun and Earth. The characteristic of near objects is that their distance is not infinite, and they are measured as a circle rather than a point in the star sensor, so when measuring angles, the center of the circle should be the target.
- Stars: The distance to the object being measured is considered infinite, so only angles can be measured, and their size in the field of view is meaningless.
Results
Using 3 stars and 2 near objects, the results are illustrated:
Result Analysis:
Modeling
Initialization Parameters
hhtmqi =[50,52,51]';% Actual position of the spacecraft (to be solved and verified)
xkxk1 =[0,0,1000]';% Coordinates of near object 1
xkxk2 =[1000,0,0]';% Coordinates of near object 2
Star Reference Frame
s1 =[1,2,3]'/(1^2+2^2+3^2)^0.5;% Unit vector of star 1
s2 =[2,1,3]'/(2^2+1^2+3^2)^0.5;% Unit vector of star 2
s3 =[3,2,1]'/(3^2+2^2+1^2)^0.5;% Unit vector of star 3
Angle Measurement Simulation
For each near object, calculate the angle between the direction of the spacecraft to that object and the directions of each star:
A11_ideal =acosd((hhtmqi-xkxk1)'/norm(hhtmqi-xkxk1)*s1);% Ideal angle
A1 =[A11_ideal,A12_ideal,A13_ideal]'+0.001*randn(3,1);% Add measurement noise
Calculation
Direction Vector Calculation
Backtrack the unit direction vector from the spacecraft to the near object through angle observations:
L1 =[cosd(A1(1)),cosd(A1(2)),cosd(A1(3))]*[s1,s2,s3]^-1;
This uses a linear equation: Direction Vector × Star Matrix = Cosine Angle Vector
Position Triangulation
Finally, using the two direction vectors and the known positions of the near objects, solve for the spacecraft’s position using the least squares method:
Ac =[L1',-L2'];% Coefficient matrix
rho =(Ac'*Ac)^-1*Ac'*(xkxk2-xkxk1);% Distance parameters
P1 = xkxk1+rho(1)*L1';% Position calculated based on near object 1
P2 = xkxk2+rho(2)*L2';% Position calculated based on near object 2
MATLAB Code
Partial Code:
% CNS(MANS) encode & decode, situation with 3 stars and 2 near objects
% Author: matlabfilter (WeChat same number, custom MATLAB code for positioning and navigation)
% 2025-09-23/Ver1
clear;clc;close all;
%% Astronomical Navigation Positioning Algorithm - Complete Version
fprintf('========== Astronomical Navigation Positioning Algorithm ==========
');
%% Initialization Parameters
hhtmqi =[50,52,51]';% Actual position of the spacecraft (to be solved and verified)
xkxk1 =[0,0,1000]';% Coordinates of near object 1
xkxk2 =[1000,0,0]';% Coordinates of near object 2
% Star vectors (normalized)
s1 =[1,2,3]'/(1^2+2^2+3^2)^0.5;% Star 1 vector
s2 =[2,1,3]'/(2^2+1^2+3^2)^0.5;% Star 2 vector
s3 =[3,2,1]'/(3^2+2^2+1^2)^0.5;% Star 3 vector
fprintf('Initial parameter settings:
');
fprintf('Actual position of the spacecraft: [%.1f, %.1f, %.1f]
',hhtmqi(1),hhtmqi(2),hhtmqi(3));
fprintf('Position of near object 1: [%.1f, %.1f, %.1f]
',xkxk1(1),xkxk1(2),xkxk1(3));
fprintf('Position of near object 2: [%.1f, %.1f, %.1f]
',xkxk2(1),xkxk2(2),xkxk2(3));
fprintf('Unit vector of star 1: [%.3f, %.3f, %.3f]
',s1(1),s1(2),s1(3));
fprintf('Unit vector of star 2: [%.3f, %.3f, %.3f]
',s2(1),s2(2),s2(3));
fprintf('Unit vector of star 3: [%.3f, %.3f, %.3f]
',s3(1),s3(2),s3(3));
%% Angle observation of near object 1
% Add measurement noise
% Backtrack direction vector through angle observation
%% Angle observation of near object 2
Full code:
https://mbd.pub/o/bread/YZWXmp9saA==