赞
踩
#include <iostream> #include <algorithm> using namespace std; double calDistance(double x1, double x2, double y1, double y2){ double s1 = pow((x1 - x2),2) + pow((y1 - y2), 2); return sqrt(s1); } void test(){ double C_x(3), C_y(0), A_x(0), A_y(0), B_x(2), B_y(2); double distance_a = calDistance(C_x, A_x, C_y, A_y); double distance_b = calDistance(A_x, B_x, A_y, B_y); double distance_c = calDistance(C_x, B_x, C_y, B_y); double s = (distance_a + distance_b + distance_c)/2; double area_tmp = s * (s - distance_a) * (s - distance_b) * (s - distance_c); area_tmp = area_tmp < 0 ? -area_tmp : area_tmp; double triangle_area = sqrt(area_tmp); double x_error = 2 * triangle_area / distance_b; cout << x_error << endl; } int main(){ test(); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。