If you have p=[x, y, z] (coordinates for point p), we need a vector v_merid=[vx, vy, vz] that is tangent to the sphere surface, that is, normal to the radius of the sphere, which joins the sphere centre (I assume it's in C=[0, 0, 0]) to p. As such it must be (p-C).v_merid=0, where . denotes the dot product. This translates to
[x, y, z]*[vx, vy, vz].'==0
in MATLAB syntax. The other conditions are that v_merid and (p-C) have two projections on plane x-y that are aligned (assuming, as seems reasonable, that the North and South pole of your sphere are on the z-axis). Then it must also hold
We need a third equation to determine the three unknowns vx, vy, vz; I will require that the vector is of unit length, so
The system can be solved analytically. The solution is implemented in the following code, where x, y, z are vectors of the same length with the coordinates of your data points.
vx=-(x.*z)./(sqrt(x.^2+y.^2));
vy=-(y.*z)./(sqrt(x.^2+y.^2));
vz=(x.^2+y.^2)./(sqrt(x.^2+y.^2));
Here, for simplicity, I have assumed that the sphere has radius R=1; if this is not the case, divide each vector by R.
The vectors can be plotted on the sphere by the command quiver3, as follows:
quiver3(x, y, z, vx, vy, vz)
The final result (assuming you have already plotted the sphere and the points) is in the following image, where I picked 20 random points on the sphere.
Best Answer