為什麼這篇MATLAB 三角形鄉民發文收入到精華區:因為在MATLAB 三角形這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者kevio (成仔)看板MATLAB標題Re: [討論] 求三角形面積時間Thu Mar 7 ...
我是沒仔細看code啦
只是我想建議
平面座標三個點構成的三角形面積
(a,b) (c,d) (e,f)
= (1/2)*| a b 1 |
| c d 1 |
| e f 1 |
(這個是行列式值)
應該這樣直接給matlab算 就會得到了
若是太多根號 浮點運算會產生很多誤差.......
※ 引述《royt (Engineer)》之銘言:
: 問題是輸入三個座標點
: 算出三點所圍成的三角形面積
: 我先用把兩點的距離分別算出來
: 再帶入海龍公式
: % MS2013 HW#1: To caculate the area of the triangular
: function area = func_hw1(x1,y1,x2,y2,x3,y3)
: % print the position
: fprintf('The first point of the triangle is (%5.2f, %5.2f)\n', x1, y1)
: fprintf('The second point of the triangle is (%5.2f, %5.2f)\n', x2, y2)
: fprintf('The third point of the triangle is (%5.2f, %5.2f)\n\n', x3, y3)
: % calculate the distance between points
: distance_12 = sqrt( (x1 - x2)^2 + (y1 - y2)^2 );
: distance_13 = sqrt( (x1 - x3)^2 + (y1 - y3)^2 );
: distance_23 = sqrt( (x2 - x3)^2 + (y2 - y3)^2 );
: % put the distance into Helen formula
: temp = (distance_12 + distance_13 + distance_23)/2;
: area = sqrt( temp * (temp - distance_12) * (temp - distance_13) * (temp -
: distance_23) );
: fprintf('The area of the triangle is %7.2', area)
: % end
: 可是測出來誤差過大 http://ppt.cc/d4sK
: 請問是哪個地方出問題嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.253.173