public class Test30 {
double x,y;
Test30(double _x,double _y){
x=_x;
y=_y;
}
public double Get(Test30 p,Test30 o){
//求余弦值
double cos=(x-p.x)*(x-o.x)+(y-p.y)*(y-o.y)/(Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y))
*Math.sqrt((x-o.x)*(x-o.x)+(y-o.y)*(y-o.y)));
//求正弦值
double sin=Math.sqrt(1-cos*cos);
//三角形求面积
double area=(Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y))
*Math.sqrt((x-o.x)*(x-o.x)+(y-o.y)*(y-o.y))*sin)/2;
return area;
}
public static void main(String[] args) {
//定义三个点求面积
Test30 a=new Test30(4.0,4.0);
Test30 b=new Test30(0.0,0.0);
Test30 c=new Test30(2.0,1.0);
System.out.println(a.Get(b,c));
}
}
这错在什么地方,结果nan,有兄弟指点下忙?