필터 지우기
필터 지우기

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 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