<<
>>
Hi, I have a question with the polyarea function
x = [0 3 3 0 0 1 1 2 2 1]; y = [0 0 3 3 0 1 2 2 1 1];
With this curve the value it gives is 8, which is correct
However I made a very similar curve
x = [0 0.4258 0.4258 0 0.009 0.4168 0.4168 0.009 0.009]; y = [0 0 0.1807 0.1807 0 0.009 0.009 0.1717 0.1717 0.009];
and the value it gives is polyarea (x, y) -> 0.1433. And the value that should give is 0.010593
someone knows why ?

3 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 30 日
The later dimensions are not the same
KSSV
KSSV 2018 年 10 月 30 日
YOu have not copied entire x. To use polyarea your order of the coordinates should follow a order..if not you will get wrong area. Give the entire x. In this case x is 1X9 and y is 1X10. So, we cannot apply polyarea.
Sergio arias fernandez
Sergio arias fernandez 2018 年 10 月 30 日
Sorry, it's true
These are the vectors x, y
x = [0 0.4258 0.4258 0 0.009 0.4168 0.4168 0.009 0.009]; y = [0 0 0.1807 0.1807 0 0.009 0.009 0.1717 0.1717 0.009]; polyarea (x, y)
the result should be 0.010593
Thank you

サインインしてコメントする。

 採用された回答

Bruno Luong
Bruno Luong 2018 年 10 月 30 日

0 投票

I think MATLAB result is right, your expectation is wrong.
Check area
>> 0.1807*0.4258-(0.1807-2*0.009)*(0.4258-2*0.009)
ans =
0.010593000000000
>>
which is the same than MATLAB

5 件のコメント

Sergio arias fernandez
Sergio arias fernandez 2018 年 10 月 30 日
x = [0 0.4258 0.4258 0 0 0.009 0.4168 0.4168 0.009 0.009]; y = [0 0 0.1807 0.1807 0 0.009 0.009 0.1717 0.1717 0.009]; polyarea(x,y)
ans=0.1433
Bruno Luong
Bruno Luong 2018 年 10 月 30 日
編集済み: Bruno Luong 2018 年 10 月 30 日
x = [0 0.4258 0.4258 0 0 0.009 0.009 0.4168 0.4168 0.009];
y = [0 0 0.1807 0.1807 0 0.009 0.1717 0.1717 0.009 0.009];
polyarea(x,y)
ans =
0.010593000000000
PS: You enter the points in wrong order for the inner rectangle
Sergio arias fernandez
Sergio arias fernandez 2018 年 10 月 30 日
Thank you very much Bruno
why this order is ok
and this order in wrong?
Bruno Luong
Bruno Luong 2018 年 10 月 30 日
編集済み: Bruno Luong 2018 年 10 月 30 日
Yes the order of the second plot is wrong; MATLAB adds (instead of subtracts) the areas of the two rectangles if they run in the same direction (anti-clockwise for both here)
Sergio arias fernandez
Sergio arias fernandez 2018 年 10 月 30 日
thanks a lot!

サインインしてコメントする。

その他の回答 (1 件)

Sergio arias fernandez
Sergio arias fernandez 2018 年 10 月 30 日

0 投票

What do you mean?
That the coordinate vectors are of different dimension? They are vectors of dimension 10 in both cases
Thank you

カテゴリ

ヘルプ センター および File Exchange で Polygonal Shapes についてさらに検索

製品

リリース

R2015b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by