http://ppt.cc/d4sK
請問是哪個地方出問題嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.214
※ royt:轉錄至看板 Math 03/07 16:27
問題是輸入三個座標點
算出三點所圍成的三角形面積
我先用把兩點的距離分別算出來
再帶入海龍公式
% 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
可是測出來誤差過大