Re: [討論] 求三角形面積

看板MATLAB作者 (成仔)時間12年前 (2013/03/07 17:26), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
我是沒仔細看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
文章代碼(AID): #1HE5rA1z (MATLAB)
討論串 (同標題文章)
文章代碼(AID): #1HE5rA1z (MATLAB)