All pastes #337404 Raw Edit

Something

public cpp v1 · immutable
·published 2007-02-02 19:40 UTC
rendered paste body
class math {public:	double Lenght(vector<Vertex> v1);	double Distance(vector<Vertex> line, vector<Vertex> point);	double Short_Dist(vector<Vertex> line, vector<Vertex> point);};double math::Lenght(vector<Vertex> v1) {	float d1, d2;	d1 = v1[0].x - v1[1].x;	d2 = v1[0].x - v1[1].y;    	return abs(sqrt(d1*d1 + d2*d2));}double math::Distance(std::vector<Vertex> line, std::vector<Vertex> point) {		double dist;	double SQ_x = point[0].x - line[0].x;	double SQ_y = point[0].y - line[0].y;     double SQ_2 = SQ_x*SQ_x + SQ_y*SQ_y;	double QS_x = SQ_x * line[1].x;	double QS_y = SQ_y * line[1].y;	double QSV_2 = QS_x * QS_x + QS_y * QS_y;	double V_2 = line[1].x * line[1].x + line[1].y + line[1].y;	dist = sqrt(SQ_2 - QSV_2/V_2);	return dist;}double math::Short_Dist(vector<Vertex> line, vector<Vertex> point) {	    vector<Vertex> P_P0, P_P1, P_Pb;	double v_x = line[0].x - line[1].x;	double v_y = line[0].y - line[1].y;	double w_x = point[0].x - line[0].x;	double w_y = point[0].y - line[0].y;	double dot_wv = v_x * w_x + v_y * w_y;	double dot_vv = v_x * v_x + v_y * v_y;	P_P0[0].x = point[0].x;  P_P0[0].y = point[0].y;	P_P0[1].x = line[0].x;   P_P0[1].y = line[0].y;    P_P1[0].x = point[0].x;  P_P1[0].y = point[0].y;	P_P1[1].x = line[1].x;   P_P1[1].y = line[1].y;	if((dot_wv) <=0) {		return Lenght(P_P0);	if((dot_vv) <= dot_wv) {		return Lenght(P_P1);	}	double b = dot_wv / dot_vv;	double Pb_x;	double Pb_y;    double bv_x, bv_y;	bv_x = b * line[0].x;	bv_y = b * line[0].y;	Pb_x = line[0].x + bv_x;	Pb_y = line[0].y + bv_y;    P_Pb[0].x = point[0].x;  P_Pb[0].y = point[0].y;	P_Pb[1].x = Pb_x;   P_Pb[1].y = Pb_y;    return Lenght(P_Pb);	}}