求三角形面积
<script>
//1.X轴坐标之差的平方加上Y轴坐标之差的平方,然后对平方和开根号就是这两点间的距离
//2.求出三角形的三边长a,b,c后,令p = (a+b+c)/2
//3.再套入以下公式就可以求出三角形的面积S :S = sqrt(p*(p-a)*(p-b)*(p-c))方法
alert(triangle(0, 0, 0, 10, 10, 10));
function triangle(x1, y1, x2, y2, x3, y3)
{
var a = dist(x1, y1, x2, y2);
var b = dist(x2, y2, x3, y3);
var c = dist(x3, y3, x1, y1);
var p = (a + b + c) / 2;
var area = Math.sqrt(p * (p - a) * (p - b) * (p - c));
return area;
};
function dist(x1, y1, x2, y2)
{
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
</script>