コード例 #1
0
ファイル: C2DLine.cpp プロジェクト: Ic3C0ld/QtGeometry7316
/**--------------------------------------------------------------------------<BR>
C2DLine::Join
\brief Function to join the 2 lines at the point where they do / would intersect. If they do then
the lines are clipped to remove the smallest part of the line. Returns false if they
cannot be joined.
<P>---------------------------------------------------------------------------*/
bool C2DLine::Join(C2DLine& Other)
{
    C2DPoint p1 = point;
    C2DPoint p2 = GetPointTo();

    C2DPoint p3 = Other.point;
    C2DPoint p4 = Other.GetPointTo();

    double Ua = (p4.x - p3.x) * (p1.y - p3.y) - (p4.y - p3.y) * (p1.x - p3.x);
    double Ub = (p2.x - p1.x) * (p1.y - p3.y) - (p2.y - p1.y) * (p1.x - p3.x);

    double dDenominator = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);

    if (dDenominator == 0)
        return false;

    Ua = Ua / dDenominator;
    Ub = Ub / dDenominator;

    C2DPoint IntPt(p1.x + Ua * (p2.x - p1.x), p1.y + Ua * (p2.y - p1.y));
    if ( Ua >=0.5)
        SetPointTo( IntPt );
    else
        SetPointFrom( IntPt );

    if ( Ub >=0.5)
        Other.SetPointTo( IntPt );
    else
        Other.SetPointFrom( IntPt );

    return true;
}
コード例 #2
0
void Tacho::draw(REAL Revs)
{
	static REAL Step = -PI/6;
	//draw the frame:
	if (CompiledList != 0)
		glCallList(CompiledList);
	else
	{
		//CompiledList = glGenLists(1);
		//glNewList(CompiledList, GL_COMPILE);

		int i;
		Point3D IntPt(0,-R_INT,0), ExtPt(0,-R_EXT,0);
		Hgl::SetColor(Color(250,130,0));
		ZRotate(IntPt,Step*(1+(MyRedLine/1000)));
		ZRotate(ExtPt,Step*(1+(MyRedLine/1000)));
		glBegin(GL_QUADS);
		for (i=0 ; i<=4 ; i++)
		{
			Hgl::Vertex(IntPt);
			Hgl::Vertex(ExtPt);
			ZRotate(IntPt,Step/3);
			ZRotate(ExtPt,Step/3);
			Hgl::Vertex(ExtPt);
			Hgl::Vertex(IntPt);
			if (i==1) Hgl::SetColor(Color(255,0,0));
		}
		glEnd();

		Hgl::SetColor(Color(255,255,255));
		glLineWidth(2);
		IntPt = Point3D(0,-R_INT,0);
		ExtPt = Point3D(0,-R_EXT,0);
		ZRotate(IntPt,Step);
		ZRotate(ExtPt,Step);
		glBegin(GL_LINES);
		for (i=0 ; i<=(MyRedLine/1000)+2 ; i++)
		{
			Hgl::Vertex(ExtPt);
			Hgl::Vertex(IntPt);
			ZRotate(IntPt,Step);
			ZRotate(ExtPt,Step);
		}
		glEnd();

		//glEndList();
	}
	//draw the needle:
	Point3D TipPt(0,-NEEDLE_LEN_F,0);
	Point3D BackPtR(-NEEDLE_WIDTH,NEEDLE_LEN_B,0);
	Point3D BackPtL(NEEDLE_WIDTH,NEEDLE_LEN_B,0);
	REAL Angle = Step*(1+min(Revs,(MyRedLine+1000))/1000);
	ZRotate(TipPt,Angle);
	ZRotate(BackPtL,Angle);
	ZRotate(BackPtR,Angle);

	Hgl::SetColor(Color(255,0,0));
	glBegin(GL_TRIANGLES);
	Hgl::Vertex(TipPt);
	Hgl::Vertex(BackPtR);
	Hgl::Vertex(BackPtL);
	glEnd();
	Hgl::SetColor(Color(255,255,255));
}