Why aren't these two polyshape objects equal?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The attached .mat file contains two polyshape objects which, according to the following, are not equal
load pgons
isequal(pi,p)
However, isn't that contradicted by the following?
isequal(pi,intersect(p,p))
isequal(pi.Vertices,p.Vertices)
For some reason, the intersection of a polyshape with itself gives rise to a different polyshape, but i can't see it in the vertex data or any of the other non-Hidden properties. What is the explanation for this?
1 commentaire
Oleg Iupikov
le 31 Mar 2021
If we debug the isequal method of polyshape class, we can see that the following condition is true:
For pi the SimplifyState = 1, and p.SimplifyState = -1. However, this property is private one. In the comment we see:
properties (Access = private)
%To indicate polyshape's simplification state
%-1: unknown 0: not simplified 1: simplified
SimplifyState
However, I'm not sure what does it mean. Maybe something to do with how those shapes were generated.
Réponse acceptée
Amal Raj
le 20 Fév 2024
Hey. The reason why the two polyshape objects pi and p are not considered equal when using the isequal function is because the isequal function checks for exact equality, including the internal representation of the objects. Even though the vertex data and other non-hidden properties may appear the same, the internal representation of the polyshape objects may differ.
When you intersect a polyshape with itself using the intersect function, it creates a new polyshape object that represents the intersection. In this case, the intersection of p with itself results in a new polyshape object that is considered equal to pi when using the isequal function.
The internal representation of polyshape objects includes additional information such as the connectivity of the vertices, which may differ even if the vertex data is the same.
If you want to check if two polyshape objects have the same shape, you can use the isvalid function to check if they are valid polyshapes, and then compare their vertex data using the isequal function.
% Check if the polyshapes are valid
isValid1 = isvalid(pi);
isValid2 = isvalid(p);
% Compare the vertex data
isEqualVertices = isequal(pi.Vertices, p.Vertices);
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Elementary Polygons 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!