Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have two points on a unit sphere. I also have their coordinates.

theta=linspace(0,2*pi,20);
phi=linspace(0,pi,20);
[theta,phi]=meshgrid(theta,phi);
rho=1;
x=rho*sin(phi).*cos(theta);
y=rho*sin(phi).*sin(theta);
z=rho*cos(phi);
mesh(x,y,z)
xyz=randn(3,2);
xyz=bsxfun(@rdivide,xyz,sqrt(sum(xyz.^2,1)));
a=xyz(:,1)';
b=xyz(:,2)';
plot3([a(1) b(1)],[a(2) b(2)],[a(3) b(3)],'r'); % Connect ab

Now I want to move both the points a and b towards each other on this unit circle by a fixed parameter( i.e. 5% of distance between them) everytime. I dont know how to do this. Please help using the code I have written as will help me understand better.

share|improve this question
add comment

1 Answer 1

You can calculate the vector to rotate each point about with the cross product, and you can calculate the distance between the two points with the norm, which can be used as a measure for the angle

you can do the rotation using rodrigues formula. see http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula

figure(1);clf
theta=linspace(0,2*pi,20);
phi=linspace(0,pi,20);
[theta,phi]=meshgrid(theta,phi);
rho=1;
x=rho*sin(phi).*cos(theta);
y=rho*sin(phi).*sin(theta);
z=rho*cos(phi);
mesh(x,y,z);hold on
% xyz=randn(3,2);
% xyz=bsxfun(@rdivide,xyz,sqrt(sum(xyz.^2,1)));
% a=xyz(:,1)';
% b=xyz(:,2)';
plot3([a(1) b(1)],[a(2) b(2)],[a(3) b(3)],'r','linewidth',4);hold on % Connect ab
angle = norm(a-b)/20; % 5 percent
v = cross(a,b)/norm(cross(a,b));
plot3([0 2*v(1)],[0 2*v(2)],[0 2*v(3)],'k');shg % Connect ab
set(gca,'dataaspectratio',[1 1 1])
a_new = a*cos( angle) + cross(v,a)*sin( angle)+v*(v.'*a)*(1-cos( angle)); % rodrigues
b_new = b*cos(-angle) + cross(v,b)*sin(-angle)+v*(v.'*b)*(1-cos(-angle)); % rodrigue
plot3([a_new(1) b_new(1)],[a_new(2) b_new(2)],[a_new(3) b_new(3)],'b','linewidth',4);shg    % Connect ab

this is checked. sorry i made a mistake in the previous edit

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.