I am doing a project related to robotics where I am using fmincon function from matlab to minimize the distance between the points x_0 and x_f. Basically task is to make manipulator move from x_0 to x_f such that it never goes out of torus region. So I think it is a constrained optimization problem. I am having difficulty in figuring out what is the strategy to find the two intermediate points (as shown in figure below) so that given x_0 and x_f, it gives us two points [x1,y1,z1] and [x2,y2,z2] to use as via points.
Can you please figure out how should I write the objective function.
The distance cost function I wrote is below, but I cannot figure out what's strategy to find the two points (via points) :
function z = objfun(x,p)
z = sqrt((p(1)-x(1))^2+(p(2)-x(2))^2+(p(3)-x(3))^2);
end