Cone containing set of points

4 views (last 30 days)
I want to enforce the constraint : " the cone with apex P and opening angle of theta must coontains point1 and point2 " P is the decision variable i need to find the cone that contains those 2 points, is there some suggestion on how to write this constraint ?
  1 Comment
Manikanta Aditya
Manikanta Aditya on 8 Apr 2024
Hi,
The constraint you’re trying to enforce can be expressed mathematically using the dot product and the definition of a cone.
Check this example to get more better understanding:
% Define the points and the apex of the cone
P = [Px, Py, Pz]; % the apex of the cone
point1 = [x1, y1, z1];
point2 = [x2, y2, z2];
% Calculate the vectors from P to the points
v1 = point1 - P;
v2 = point2 - P;
% Calculate the cosine of the angle between the vectors
cos_angle = dot(v1, v2) / (norm(v1) * norm(v2));
% Check if the points are within the cone
if cos_angle > cosd(theta)
disp('The points are within the cone.')
else
disp('The points are not within the cone.')
end
Thanks.

Sign in to comment.

Accepted Answer

Hassaan
Hassaan on 8 Apr 2024
% Define the opening angle theta (in radians), and two points
theta = pi / 6; % Example value for theta
point1 = [1, 2, 3]; % Example value for point1
point2 = [4, 5, 6]; % Example value for point2
% Initial guess for P (the apex of the cone)
P0 = [0, 0, 0]; % Adjust as necessary
% Optimization options
options = optimoptions('fmincon', 'Display', 'iter', 'Algorithm', 'sqp');
% Define the objective function as a handle to an anonymous function
objectiveFunction = @(P) 0; % Dummy objective function
% Define the nonlinear constraint as an anonymous function
coneConstraint = @(P) deal(...
[cos(pi/6) - dot(point1 - P, (point1 + point2)/2 - P) / (norm(point1 - P) * norm((point1 + point2)/2 - P)), ...
cos(pi/6) - dot(point2 - P, (point1 + point2)/2 - P) / (norm(point2 - P) * norm((point1 + point2)/2 - P))], ...
[]);
% Running the optimization
[Popt, fval, exitflag, output] = fmincon(objectiveFunction, P0, [], [], [], [], [], [], coneConstraint, options);
Iter Func-count Fval Feasibility Step Length Norm of First-order step optimality 0 4 0.000000e+00 0.000e+00 1.000e+00 0.000e+00 0.000e+00 Initial point is a local minimum that satisfies the constraints. Optimization completed because at the initial point, the objective function is non-decreasing in feasible directions to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
if exitflag > 0
fprintf('Optimization succeeded. Optimal apex of the cone is:\n');
disp(Popt);
else
fprintf('Optimization did not converge to a solution.\n');
end
Optimization succeeded. Optimal apex of the cone is:
0 0 0
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

More Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!