作者kevio (成仔)
看板MATLAB
标题Re: [讨论] 求三角形面积
时间Thu Mar 7 17:26:31 2013
我是没仔细看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