Cone containing set of points

2 次查看(过去 30 天)
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 个评论
Manikanta Aditya
Manikanta Aditya 2024-4-8
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.

请先登录,再进行评论。

采纳的回答

Hassaan
Hassaan 2024-4-8
% 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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by