Cone containing set of points
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ouassim Benhamouche
le 8 Avr 2024
Commenté : Ouassim Benhamouche
le 8 Avr 2024
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 commentaire
Manikanta Aditya
le 8 Avr 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.
Réponse acceptée
Hassaan
le 8 Avr 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);
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
-----------------------------------------------------------------------------------------------------------------------------------------------------
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Denoising and Compression dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!