フィルターのクリア

Why aren't these two polyshape objects equal?

3 ビュー (過去 30 日間)
Matt J
Matt J 2021 年 3 月 30 日
回答済み: Amal Raj 2024 年 2 月 20 日
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 Center および File ExchangeElementary Polygons についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by