Fw: [討論] 求三角形面積
※ [本文轉錄自 MATLAB 看板 #1HE4qka_ ]
作者: royt (Engineer) 看板: MATLAB
標題: [討論] 求三角形面積
時間: Thu Mar 7 16:17:47 2013
問題是輸入三個座標點
算出三點所圍成的三角形面積
我先用把兩點的距離分別算出來
再帶入海龍公式
% 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.112.7.214
※ 發信站: 批踢踢實業坊(ptt.cc)
※ 轉錄者: royt (140.112.7.214), 時間: 03/07/2013 16:27:39
→
03/07 17:06, , 1F
03/07 17:06, 1F
→
03/07 17:06, , 2F
03/07 17:06, 2F
→
03/07 17:09, , 3F
03/07 17:09, 3F
推
03/07 20:05, , 4F
03/07 20:05, 4F
→
03/07 20:15, , 5F
03/07 20:15, 5F
推
03/07 22:00, , 6F
03/07 22:00, 6F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):