コード例 #1
0
	point2f pc_rc_transformer::to_pc(const point2f & real_cordinate) const
	{
		for(unsigned int n = 0; n < fiducials_real_coordinates.size(); n++)
		{
			if(fiducials_real_coordinates[n] == real_cordinate)
			{
				return fiducials_pixel_coordinates[n];
			}
		}
		point2f intersection0, intersection1;
		std::list<point2f> intersections;

		for(unsigned int n = 0; n < fiducials_real_coordinates.size(); n++)
		{
			for(unsigned int m = n+1; m < fiducials_real_coordinates.size(); m++)
			{
				if(!circle_circle_intersection( fiducials_pixel_coordinates[n],
														real_cordinate.distance(fiducials_real_coordinates[n])/scale,
														fiducials_pixel_coordinates[m],
														real_cordinate.distance(fiducials_real_coordinates[m])/scale,
														intersection0,
														intersection1))
				{
					throw std::runtime_error("Can not find two intersections between the circles");
				}
				intersections.push_back(intersection0);
				intersections.push_back(intersection1);
			}
		}

		point2f result;
		std::list<point2f>::iterator index_intersection0;
		std::list<point2f>::iterator index_intersection1;

		for(unsigned int n= 0; n < fiducials_pixel_coordinates.size()-1; n++)
		{
			double shortest_distance = DBL_MAX;

			for(std::list<point2f>::iterator i = intersections.begin(); i != intersections.end(); i++)
			{
				std::list<point2f>::iterator j = i;
				++j;
				for(; j != intersections.end(); j++)
				{
					double temp = (*i).distance(*j);
					if(temp < shortest_distance)
					{
						shortest_distance = temp;
						index_intersection0 = i;
						index_intersection1 = j;
					}
				}
			}
			result = (*index_intersection0).mean(*index_intersection1);
			intersections.erase(index_intersection0);
			intersections.erase(index_intersection1);
			intersections.push_back(result);
		}
		return result;
	}
コード例 #2
0
ファイル: circle.c プロジェクト: bart9h/cave9
void run_test(double x0, double y0, double r0,
		double x1, double y1, double r1)
{
	double x3, y3, x3_prime, y3_prime;

	printf("x0=%F, y0=%F, r0=%F, x1=%F, y1=%F, r1=%F :\n",
			x0, y0, r0, x1, y1, r1);
	circle_circle_intersection(x0, y0, r0, x1, y1, r1,
			&x3, &y3, &x3_prime, &y3_prime);
	printf("  x3=%F, y3=%F, x3_prime=%F, y3_prime=%F\n",
			x3, y3, x3_prime, y3_prime);
}
コード例 #3
0
ファイル: LappedUtils.cpp プロジェクト: hillsalex/Darkon
//Assuming A and B have correct UV coords and world space coords, return an estimate of C's UV coords
vec2<float> LappedUtils::estimateUV(PatchVert* A, PatchVert* B, PatchVert* C, vec2<float> *_Ast, vec2<float> *_Bst, vec2<float> *_Otherst)
{


    vec2<float> Ast,Bst,Otherst;
    Ast.x = _Ast->x;
    Ast.y = _Ast->y;
    Bst.x = _Bst->x;
    Bst.y = _Bst->y;
    Otherst.x = _Otherst->x;
    Otherst.y = _Otherst->y;


    vec2<float> abst = Bst-Ast;
    double ABlengthp = sqrt(abst.x*abst.x+abst.y*abst.y);
    double ABlength = (B->pos-A->pos).getMagnitude();
    double AClength = (C->pos-A->pos).getMagnitude();
    double BClength = (C->pos-B->pos).getMagnitude();
    double scaleFactor = ABlengthp/ABlength;
    double BClengthp = BClength*scaleFactor;
    double AClengthp = AClength*scaleFactor;

    double *_f1x,*_f1y,*_f2x,*_f2y;
    _f1x = new double;
    _f1y = new double;
    _f2x = new double;
    _f2y = new double;
    int f = circle_circle_intersection(_Ast->x,_Ast->y,AClengthp,_Bst->x,_Bst->y,BClengthp,_f1x,_f1y,_f2x,_f2y);
    vec2<float> f1 = vec2<float>(*_f1x,*_f1y);
    vec2<float> f2 = vec2<float>(*_f2x,*_f2y);


    /*double lawofcosines = (BClengthp*BClengthp)/(AClengthp*AClengthp+ABlengthp*ABlengthp-2*AClengthp*ABlengthp);
    double theta = acos((BClengthp*BClengthp)/(AClengthp*AClengthp+ABlengthp*ABlengthp-2*AClengthp*ABlengthp));
    double endbase = AClengthp*cos(theta);
    double endheight = AClengthp*sin(theta);
    //cout<<"ABlengthp: "<<ABlengthp<<" ABlength: "<<ABlength<<" AClength: "<<AClength<<" BClength: "<<BClength<<" scaleFactor: "<<scaleFactor<<""
    vec2<float>pabst = abst/ABlengthp;
    vec2<float>pabstr1 = vec2<float>(-pabst.y,pabst.x);
    vec2<float>pabstr2 = -pabstr1;
    vec2<float>final1 = pabst*endbase+abst;
    vec2<float>final2 = final1;
    final1 = final1 + pabstr1*endheight;
    final2 = final2 + pabstr2*endheight;
    */
    vec2<float>d1,d2;
    d1.x = Otherst.x- (*_f1x);
    d1.y = Otherst.y- (*_f1y);
    d2.x = Otherst.x- (*_f2x);
    d2.y = Otherst.y- (*_f2y);

    // cout << "RESULTS: " << endl << final1 << endl << final2 << endl;

    // cout << "ENDING" << endl;



    if ((d1.x*d1.x+d1.y*d1.y)>(d2.x*d2.x+d2.y*d2.y))
        return vec2<float>(*_f1x,*_f1y);
    else return vec2<float>(*_f2x,*_f2y);





    /*

    Vector4 AC = C->pos - A->pos;
    Vector4 AB = B->pos - A->pos;

    Vector4 AB_r = AB * getRotMat(Vector4(A->pos.x,A->pos.y,A->pos.z,0),AC.cross(AB),M_PI/2.0);
    float x = AC.dot(AB) / AB.getMagnitude2();
    float y = AC.dot(AB_r) / AB.getMagnitude2();

    //these are UVS
    vec2<float> ABp,AB_rp;
    ABp.x = Bst.x - Ast.x;
    ABp.y = Bst.y - Ast.y;
    AB_rp.x = ABp.y;
    AB_rp.y = -ABp.x;



    vec2<float> Cp; //Ap,Bp
    // Ap.x = Ast.x; Ap.y = Ast.y; Bp.x = B->s; Bp.y = B->t;
    Cp = Ast + x*ABp + y*AB_rp;






    AC = C->pos - B->pos;
    AB = A->pos - B->pos;

    AB_r = AB * getRotMat(Vector4(B->pos.x,B->pos.y,B->pos.z,0),AC.cross(AB),M_PI/2.0);
    x = AC.dot(AB) / AB.getMagnitude2();
    y = AC.dot(AB_r) / AB.getMagnitude2();

    //these are UVS
    ABp,AB_rp;
    ABp.x = Bst.x - Ast.x;
    ABp.y = Bst.y - Ast.y;
    AB_rp.x = ABp.y;
    AB_rp.y = -ABp.x;



    vec2<float> Cp2; //Ap,Bp
    // Ap.x = Ast.x; Ap.y = Ast.y; Bp.x = B->s; Bp.y = B->t;
    Cp2 = Ast + x*ABp + y*AB_rp;

    vec2<float>CP1 = Cp-Otherst;
    vec2<float>CP2 = Cp2-Otherst;

    return Cp2;

    if ((CP1.x*CP1.x+CP1.y*CP1.y)>(CP2.x*CP2.x+CP2.y*CP2.y))
        return Cp2;
    else
        return Cp;

    //cout<<"AB: "<<AB<<" AC: "<<AC<<" AB_r: "<<AB_r<<" ABp: "<<ABp<<" AB_rp: "<<AB_rp<<" x: "<<x<<" y: "<<y<<" Ap:"<<Ap<<" Bp: "<<Bp<<" Cp: "<<Cp<<endl;
    //cout<<"AC dot AB: "<<AC.dot(AB)<<" AB dot AC: "<<AB.dot(AC)<<" mag AB: "<<AB.getMagnitude()<<endl;
        */
}