由在三点坐标求三角形面积
2010-12-13 09:19
351 查看
由在三点坐标求三角形面积
首先求三边边长:
a b c
用海伦公式求面积:
三角形的面积 area=sqrt( p*(p- a) * (p - b) * (p - c) )
其中p = (a + b + c) / 2;
源码:
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
float x,y;
public:
Point(float x1=0,float y1=0)//:x(x1),y(y1)
{
x=x1;
y=y1;
}
float getX()
{
return x;
}
float getY()
{
return y;
}
//friend float GetDistancebyPoint(Point Pa,Point Pb);
};
class Triangle
{
Point a;
Point b;
Point c;
public:
Triangle(Point a1,Point b1,Point c1):a(a1),b(b1),c(c1)
{}
float GetDistancebyPoint(Point Pa,Point Pb)
{
return sqrt (abs(Pa.getX() - Pb.getX())*abs(Pa.getX() - Pb.getX()) + abs(Pa.getY() - Pb.getY()) * abs(Pa.getY() - Pb.getY()));
}
float area()
{
float p = 0.0;
float a1=GetDistancebyPoint(a,b);
float b1=GetDistancebyPoint(a,c);
float c1=GetDistancebyPoint(b,c);
p = (a1 + b1 + c1) / 2;
return (sqrt(p * (p - a1) * (p - b1) * (p - c1)));
}
};
int main()
{
Point a(0,0);
Point b(1,2);
Point c(2,0);
Triangle t(a,b,c);
cout<<"三角形面积为:"<<t.area()<<endl;
return 0;
}
首先求三边边长:
a b c
用海伦公式求面积:
三角形的面积 area=sqrt( p*(p- a) * (p - b) * (p - c) )
其中p = (a + b + c) / 2;
源码:
#include <iostream>
#include <cmath>
using namespace std;
class Point
{
float x,y;
public:
Point(float x1=0,float y1=0)//:x(x1),y(y1)
{
x=x1;
y=y1;
}
float getX()
{
return x;
}
float getY()
{
return y;
}
//friend float GetDistancebyPoint(Point Pa,Point Pb);
};
class Triangle
{
Point a;
Point b;
Point c;
public:
Triangle(Point a1,Point b1,Point c1):a(a1),b(b1),c(c1)
{}
float GetDistancebyPoint(Point Pa,Point Pb)
{
return sqrt (abs(Pa.getX() - Pb.getX())*abs(Pa.getX() - Pb.getX()) + abs(Pa.getY() - Pb.getY()) * abs(Pa.getY() - Pb.getY()));
}
float area()
{
float p = 0.0;
float a1=GetDistancebyPoint(a,b);
float b1=GetDistancebyPoint(a,c);
float c1=GetDistancebyPoint(b,c);
p = (a1 + b1 + c1) / 2;
return (sqrt(p * (p - a1) * (p - b1) * (p - c1)));
}
};
int main()
{
Point a(0,0);
Point b(1,2);
Point c(2,0);
Triangle t(a,b,c);
cout<<"三角形面积为:"<<t.area()<<endl;
return 0;
}
相关文章推荐
- 已知三点坐标,求三角形面积(转载)
- 三点坐标求三角形面积(数学)
- 已知三角形三点坐标,求三角形的面积
- 已知三角形三点坐标, 求三角形的面积
- 已知三维空间内三点坐标,求三角形面积(简单)
- BugZhu抽抽抽!!(已知三角形三点坐标,求外接圆半径及三角面积)
- HDU BugZhu抽抽抽!! 知道三点坐标,求三角形面积,外接圆面积,半径
- nyoj815三角形(已知三角形的三边长或三顶点坐标求面积)&& nyoj68三点顺序(向量叉积)
- 已知三角形三点坐标,求三角形的面积
- 已知三角形三点坐标,求三角形的面积(二维和三维)
- 通过三点坐标求三角形面积
- 已知三点坐标求三角形面积
- 关于已知三角形三点坐标求三角形面积
- 三点坐标求三角形的面积
- 用C++完成 根据三点坐标求三角形面积 功能
- 计算几何(知三角形三点坐标,求三角形的面积)
- 三角形面积,三点顺序
- 已知三角形三顶点坐标,求三角形面积的表达式 找出求果园里的树的解决方案
- 已知三点,求三角形面积