Borrar filtros
Borrar filtros

Why aren't these two polyshape objects equal?

3 visualizaciones (últimos 30 días)
Matt J
Matt J el 30 de Mzo. de 2021
Respondida: Amal Raj el 20 de Feb. de 2024
The attached .mat file contains two polyshape objects which, according to the following, are not equal
load pgons
isequal(pi,p)
ans = logical
0
However, isn't that contradicted by the following?
isequal(pi,intersect(p,p))
ans = logical
1
isequal(pi.Vertices,p.Vertices)
ans = logical
1
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 comentario
Oleg Iupikov
Oleg Iupikov el 31 de Mzo. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Amal Raj
Amal Raj el 20 de Feb. de 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);

Más respuestas (0)

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by