Why aren't these two polyshape objects equal?

3 次查看(过去 30 天)
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 个评论
Oleg Iupikov
Oleg Iupikov 2021-3-31
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.

请先登录,再进行评论。

采纳的回答

Amal Raj
Amal Raj 2024-2-20
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 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by