예제 #1
0
파일: pro.c 프로젝트: ashrithhc/blindfold
void n8(float x,float y,float h,float w)
{
 glBegin(GL_POINTS);
 cir(x+w/2,y+3*h/4,h/4);
 cir(x+w/2,y+h/4,h/4);
 glEnd();
 xnxt+=w;
 xnxt+=sp;
}
예제 #2
0
void test_flash_led()
{
	ngac ac("ac1", 0, 5, 1);
	ngresistor r("r1", 370);
	ngled led("led1", 5e-3);
	ngground gnd;

	ngline l0(ac.p1, gnd.p1);
	ngline l1(ac.p2, r.p1);
	ngline l2(r.p2, led.p1);
	ngline l3(led.p2, ac.p1);

	schema sch;
	sch.AddDevices(&ac, &r, &led, &gnd, 0);
	sch.AddLines(&l0, &l1, &l2, &l3, 0);

	circuit cir(&sch);
	cir.Tran("2", "10m");

	do 
	{
		Sleep(200);

	} while (cir.IsRunning());
	
	getchar();
}
예제 #3
0
void test_circuit_rc()
{
	ngdc dc("dc1", 5);
	ngresistor r("r1", 5);
	ngcapacitor c("c1", 0.2);
	ngground gnd;

	ngline line1(dc[0], r[0]);
	ngline line2(r[1], c[0]);
	ngline line3(c[1], dc[1]);
	ngline line4(dc[0], gnd[0]);

	schema sch("design1");
	sch.AddDevice(&dc);
	sch.AddDevice(&r);
	sch.AddDevice(&c);
	sch.AddDevice(&gnd);

	sch.AddLine(&line1);
	sch.AddLine(&line2);
	sch.AddLine(&line3);
	sch.AddLine(&line4);

	circuit cir(&sch);
	cir.Tran("1s");
	
	do 
	{
		Sleep(200);
	} while (cir.IsRunning());
}
예제 #4
0
void test_restart()
{
	ngac ac("ac1", 0, 5, 1);
	ngresistor r("r1", 370);
	ngled led("led1", 5e-3);
	ngground gnd;

	ngline l0(ac.p1, gnd.p1);
	ngline l1(ac.p2, r.p1);
	ngline l2(r.p2, led.p1);
	ngline l3(led.p2, ac.p1);

	schema sch;
	sch.AddDevices(&ac, &r, &led, &gnd, 0);
	sch.AddLines(&l0, &l1, &l2, &l3, 0);

	circuit cir(&sch);
	cir.Tran("1000");

	do 
	{
		Sleep(200);
		char ch = getchar();
		switch (ch)
		{
		case 'r':
			cir.Restart();
			Sleep(200);
			break;
		default:
			break;
		}
	} while (cir.IsRunning());
}
예제 #5
0
void test_switch_by_csw()
{
	ngdc dc("dc1", 5);
	ngspst spst("spst", ngspst::on);
	ngresistor r("1", 5);
	ngled led("led");
	ngground gnd;

	ngline l1(dc.pos, spst.p1);
	ngline l2(spst.p2, r.p1);
	ngline l3(r.p2, led.pos);
	ngline l4(led.neg, dc.neg);
	ngline l0(dc.neg, gnd.ground);

	schema sch;
	sch.AddDevices(&dc, &spst, &r, &gnd, &led, 0);
	sch.AddLines(&l1, &l2, &l3, &l0, &l4, 0);

	circuit cir(&sch);

#if 0//not work
	// tran with spst disconnected
	cir.Tran("10", "1m");
	do 
	{
		Sleep(100);
	} while (cir.IsRunning());
	//cir.Stop();

	// tran with spst connected, however it's still disconnected
	string sw = spst.switchover();
	cir.Do(sw);
	cir.Tran("10", "1m");
	do 
	{
		Sleep(100);
	} while (cir.IsRunning());
#endif


	// run with event input to switch spst
	cir.Tran("1t", "1m", 0);
	do 
	{
		Sleep(200);
		char ch = getchar();
		switch (ch)
		{
		case 'a':
			cir.SwitchOver(&spst);
			Sleep(200);
			break;
		case 'q':
			cir.Halt();
		default:
			break;
		};
	} while (cir.IsRunning());
}
예제 #6
0
파일: pro.c 프로젝트: ashrithhc/blindfold
void n9(float x,float y,float h,float w)
{
 glBegin(GL_POINTS);
 cir(x+w/2,y+3*h/4,h/4);
 sem34(x+w/2,y+h/4,h/4);
 mid(x+w,y+h/4,x+w,y+3*h/4);
 glEnd();
 xnxt+=w;
 xnxt+=sp;
}
int main()
{
	int gd=DETECT,gm;
	initgraph(&gd,&gm,NULL);
	int x=50,y=50,r=10;
	cir(x,y,r);
	getch();
	closegraph();

}
예제 #8
0
int main()
   {
   init_graphics();           //initialize graphics system

   circle cir(40, 12, 5, cBLUE, X_FILL);      //create circle
   rect rec(12, 7, 10, 15, cRED, SOLID_FILL); //create rectangle
   tria tri(60, 7,  11, cGREEN, MEDIUM_FILL); //create triangle

   cir.draw();                //draw all shapes
   rec.draw();
   tri.draw();
   set_cursor_pos(1, 25);     //lower left corner
   return 0;
   }
예제 #9
0
void test_spdt()
{
	//创建所需元器件
	ngdc dc("dc1", 5);
	ngspdt spdt("spdt", ngspdt::status_throw1);
	ngresistor r1("1", 5);
	ngresistor r2("2", 5);
	ngled led1("led1");
	ngled led2("led2");
	ngground gnd;

	//创建接线,连接各元器件
	ngline l1(dc.pos, spdt.pole);
	ngline l2(spdt.throw1, r1.p1);
	ngline l3(spdt.throw2, r2.p1);
	ngline l4(r1.p2, led1.pos);
	ngline l5(r2.p2, led2.pos);
	ngline l6(led1.neg, dc.neg);
	ngline l7(led2.neg, dc.neg);
	ngline l0(dc.neg, gnd.ground);

	//创建电路图,添加元器件、接线到电路图
	schema sch;
	sch.AddDevices(&dc, &spdt, &r1, &r2, &led1, &led2, &gnd, 0);
	sch.AddLines(&l1, &l2, &l3, &l4, &l5, &l6, &l7, &l0, 0);

	//创建仿真对象,添加电路图,并开始暂态仿真
	circuit cir(&sch);
	cir.Tran("1t", "1m", 0);
	do 
	{
		Sleep(200);
		char ch = getchar();
		switch (ch)
		{
		case 'a':
			cir.SwitchOver(&spdt);
			Sleep(200);
			break;
		case 'q':
			cir.Halt();
		default:
			break;
		};
	} while (cir.IsRunning()); //主程序线程,类似windows UI消息循环
}
예제 #10
0
void test_circuit_rc_tran()
{
	ngdc dc("dc1", 5);
	ngspdt spdt("spdt");
	ngresistor r("r1", 5);
	ngcapacitor c("c1", 0.2);
	ngground gnd;

	ngline line1(dc.pos, spdt.throw1);
	ngline line2(spdt.pole, r.p1);
	ngline line3(r.p2, c.p1);
	ngline line4(c.p2, dc.neg);
	ngline line5(spdt.throw2, gnd.ground);
	ngline line0(dc.neg, gnd.ground);

	schema sch;
	sch.AddDevices(&dc, &spdt, &r, &c, &gnd, 0);
	sch.AddLines(&line1, &line2, &line3, &line4, &line5, &line0, 0);


	circuit cir(&sch);
	cir.Tran("1t", "100u");

	do 
	{
		Sleep(200);
		char ch = getchar();
		switch (ch)
		{
		case 'a':
			// switchover to charge or discharge
			cir.SwitchOver(&spdt);
			Sleep(200);
			break;
		case 'q':
			cir.Halt();
		default:
			break;
		};
	} while (cir.IsRunning());

	cir.Do("plot all");
}
예제 #11
0
void test_circuit_parallel()
{
	//circuit 1
	ngac AC("ac1", 0, 5, 1);
	ngresistor R("r1", 370);
	ngled LED("LED1", 7e-3);
	ngground GND;

	ngline L0(AC.p1, GND.p1);
	ngline L1(AC.p2, R.p1);
	ngline L2(R.p2, LED.p1);
	ngline L3(LED.p2, AC.p1);

	schema SCH;
	SCH.AddDevices(&AC, &R, &LED, &GND, 0);
	SCH.AddLines(&L0, &L1, &L2, &L3, 0);

	circuit CIR(&SCH);
	CIR.Tran("20", "1m");

	//circuit 2
	ngac ac("ac1", 0, 5, 1);
	ngresistor r("r1", 370);
	ngled led("led1", 5e-3);
	ngground gnd;

	ngline l0(ac.p1, gnd.p1);
	ngline l1(ac.p2, r.p1);
	ngline l2(r.p2, led.p1);
	ngline l3(led.p2, ac.p1);

	schema sch;
	sch.AddDevices(&ac, &r, &led, &gnd, 0);
	sch.AddLines(&l0, &l1, &l2, &l3, 0);

	circuit cir(&sch);
	cir.Tran("20", "1m");

	do 
	{
		Sleep(200);
	} while (CIR.IsRunning() || cir.IsRunning());
}
예제 #12
0
void test_switch_by_resistor()
{
	ngdc dc("dc", 10);
	ngresistor r("r1", 370);
	ngled led("led1", 5e-3);
	ngswitch sw("sw", ngswitch::off);
	ngground gnd;

	ngline l0(dc.neg, gnd.p1);
	ngline l1(dc.pos, r.p1);
	ngline l2(r.p2, led.p1);
	ngline l3(led.p2, sw.p1);
	ngline l4(sw.p2, dc.neg);

	schema sch;
	sch.AddDevices(&dc, &r, &led, &gnd, &sw, 0);
	sch.AddLines(&l0, &l1, &l2, &l3, &l4, 0);

	circuit cir(&sch);
	cir.Tran("1t", "1m");

	do 
	{
		Sleep(200);
		char ch = getchar();
		switch (ch)
		{
		case 'a':
			cir.SwitchOver(&sw);
			Sleep(200);
			break;
		case 'q':
			cir.Halt();
		default:
			break;
		};
	} while (cir.IsRunning());

}
예제 #13
0
/* same effect to test_rc_charge_discharge()
title rc charge discharge
.global gnd
vdc1 1 0 dc 5.000e+000
xspdt 1 2 0 spdt
rr1 2 3 5.000e+000
cc1 3 0 2.000e-001

.subckt spdt 1 2 3 params: vstatus=0 ron=1e-8 roff=1e30
r1 0 6 20
v1 6 0 dc {vstatus}
w0 2 1 v1 nc_contact
w1 2 3 v1 no_contact
.model no_contact csw (it=0.05 ih=0.025 ron={ron} roff={roff})
.model nc_contact csw (it=0.05 ih=0.025 ron={roff} roff={ron})
.ends

.control
stop when time = 5s
tran 100u 10s uic
alter v.xspdt.v1=-2
resume
plot all
.endc
*/
void test_rc_charge_discharge()
{
	ngdc dc("dc1", 5);
	ngspdt spdt("spdt");
	ngresistor r("r1", 5);
	ngcapacitor c("c1", 0.2);
	ngground gnd;

	ngline line1(dc.pos, spdt.throw1);
	ngline line2(spdt.pole, r.p1);
	ngline line3(r.p2, c.p1);
	ngline line4(c.p2, dc.neg);
	ngline line5(spdt.throw2, gnd.ground);
	ngline line0(dc.neg, gnd.ground);

	schema sch;
	sch.AddDevices(&dc, &spdt, &r, &c, &gnd, 0);
	sch.AddLines(&line1, &line2, &line3, &line4, &line5, &line0, 0);

	circuit cir(&sch);
	// transient analysis last 10 seconds
	cir.Tran("10", "1m");
	do 
	{
		Sleep(100);
		//charge 5 seconds. when time passes 5 seconds, start to discharge.
		static bool done = false;
		if (cir.CurrentValue("time") >= 5 && !done)
		{
			cir.SwitchOver(&spdt);
			Sleep(200);
			done = true;
		}
	} while (cir.IsRunning());
	cir.Do("plot all");
	getchar();
}
예제 #14
0
void test_switch_by_csw_inter()
{
	ngdc dc("dc1", 5);
	ngspst spst("spst");
	ngresistor r("1", 5);
	ngground gnd;

	ngline l1(dc.pos, spst.p1);
	ngline l2(spst.p2, r.p1);
	ngline l3(r.p2, dc.neg);
	ngline l0(dc.neg, gnd.ground);

	schema sch;
	sch.AddDevices(&dc, &spst, &r, &gnd, 0);
	sch.AddLines(&l1, &l2, &l3, &l0, 0);

	circuit cir(&sch);

#if 1//ok now
	vector<string> netlist = sch.GetNetlist();
	// tran with spst disconnected
	printf("-----spst disconnected---------\n");
	cir.LoadNetlist(netlist);
	cir.Do("listing");
	cir.Do("tran 1m 10 uic");


	// tran with spst connected
	printf("-----spst connected---------\n");
	string sw = spst.switchover();
	cir.Do(sw.c_str());
	cir.Do("listing");
	cir.Do("tran 1m 10 uic");

#endif
}
예제 #15
0
void freeKick6::setPositions()
{
    Position leftDefPos,rightDefPos,goaliePos;
    int leftID = -1, rightID = -1 , midID = -1;
    bool rightNav , leftNav;

    if( wm->ourRobot[tDefenderLeft->getID()].Role == AgentRole::DefenderLeft )
        leftID = tDefenderLeft->getID();

    if( wm->ourRobot[tDefenderRight->getID()].Role == AgentRole::DefenderRight )
        rightID = tDefenderRight->getID();

    if( leftChecker > 100 || leftID == -1 )
        midID = rightID;

    if( rightChecker > 100  || rightID == -1)
        midID = leftID;

    zonePositions(leftID,rightID,midID,goaliePos,leftDefPos,leftNav,rightDefPos,rightNav);

    tGolie->setIdlePosition(goaliePos);
    tDefenderLeft->setIdlePosition(leftDefPos);
    tDefenderLeft->setUseNav(leftNav);
    tDefenderRight->setIdlePosition(rightDefPos);
    tDefenderRight->setUseNav(rightNav);

    if( leftID != -1)
    {
        if( (wm->ourRobot[leftID].pos.loc - leftDefPos.loc).length() > 250 )
            leftChecker++;
        else
            leftChecker = 0;
    }

    if( rightID != -1)
    {
        if( (wm->ourRobot[rightID].pos.loc - rightDefPos.loc).length() > 250 )
            rightChecker++;
        else
            rightChecker = 0;
    }

    Position pos;

    QList<int> ourAttackers = wm->kn->findAttackers();
    ourAttackers.removeOne(tAttackerMid->getID());

    QList<int> ourPlayers = wm->kn->ActiveAgents();
    Positioning voronoi;
    voronoi.setWorldModel(wm);
    bool isMatched;

    QList<Positioning_Struct> positions = voronoi.kickPositions(ourAttackers,target,isMatched);

    for(int i=0;i<positions.size();i++)
    {
        Positioning_Struct tmp = positions.at(i);
        ourPlayers.removeOne(tmp.ourI);

        switch (wm->ourRobot[tmp.ourI].Role) {
        case AgentRole::AttackerLeft:
            pos.loc = tmp.loc;
            pos.dir = (Field::oppGoalCenter - pos.loc).dir().radian();
            tAttackerLeft->setIdlePosition(pos);
            break;
        case AgentRole::AttackerRight:
            pos.loc = tmp.loc;
            pos.dir = (Field::oppGoalCenter - pos.loc).dir().radian();
            tAttackerRight->setIdlePosition(pos);
            break;
        default:
            break;
        }
    }

    if( state == 0)
    {
        if( checkAttackersDistance() )
            state = 1;
    }

    for(int i=0;i<ourPlayers.size();i++)
    {
        switch (wm->ourRobot[ourPlayers.at(i)].Role) {
        case AgentRole::DefenderLeft:
            if( state != 0)
            {
                Vector2D first,second,final;
                Line2D t2t(wm->ball.pos.loc, Field::oppGoalCenter);
                Circle2D cir(wm->ball.pos.loc ,ALLOW_NEAR_BALL_RANGE+100);
                cir.intersection(t2t,&first,&second);
                if( wm->ball.pos.loc.x < first.x)
                    final = first;
                else
                    final = second;
                pos.loc = final;
                pos.dir = (Field::oppGoalCenter - wm->ball.pos.loc).dir().radian();
                tDefenderLeft->setIdlePosition(pos);

                if( wm->kn->ReachedToPos(wm->ourRobot[tDefenderLeft->getID()].pos.loc
                                         ,pos.loc, 95))
                state = 2;
            }
            break;
        case AgentRole::AttackerMid:
            if( state == 1)
            {
                pos.loc = Vector2D(wm->ball.pos.loc.x-200,wm->ball.pos.loc.y);
                pos.dir = 0;
                tAttackerMid->setIdlePosition(pos);
            }
            else if(state == 0)
                tAttackerMid->setIdlePosition(wm->ourRobot[tAttackerMid->getID()].pos);
            break;
        default:
            break;
        }
예제 #16
0
	AcDbIntArray &   geomIds) const
#else
Acad::ErrorStatus PDEcone::getOsnapPoints(
	AcDb::OsnapMode       osnapMode,
	int                   gsSelectionMark,
	const AcGePoint3d&    pickPoint,
	const AcGePoint3d&    lastPoint,
	const AcGeMatrix3d&   viewXform,
	AcGePoint3dArray&     snapPoints,
	AcDbIntArray&         geomIds) const
#endif
{
    assertReadEnabled();

    if(!hasSnap())
        return Acad::eOk;

	int gsSelectionMark_int = (int)gsSelectionMark;
    if(gsSelectionMark_int == 0)
        return Acad::eOk;

    AcGePoint3dArray pArray;
    AcGeIntArray stdIdx;
    int actPrecision;
    getVertices(m_dDividPrecision, pArray, stdIdx, actPrecision);
    int actPrecision__1 = actPrecision + 1;
    int stdIdxLen = stdIdx.length();
    int stdIdxLen_1 = stdIdxLen - 1;
    int stdIdxLen____2 = stdIdxLen / 2;

    AcGeVector3d viewDir(viewXform(Z, 0), viewXform(Z, 1),
                         viewXform(Z, 2));
    AcGeVector3d vect = getFaceVect();

    int i;
    switch(osnapMode)
    {
    case AcDb::kOsModeEnd:
        snapPoints.append(m_ptStart);
		snapPoints.append(m_ptEnd);
        for(i = 0; i < stdIdxLen_1; ++i)
        {
            snapPoints.append(pArray[stdIdx[i]]);
            snapPoints.append(pArray[stdIdx[i] + actPrecision__1]);
        }
		break;
    case AcDb::kOsModeMid:
        snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 2.0);
        for(i = 0; i < stdIdxLen_1; ++i)
            snapPoints.append(pArray[stdIdx[i]] + 
                              (pArray[stdIdx[i] + actPrecision__1] - pArray[stdIdx[i]]) / 2.0);
        break;
    case AcDb::kOsModeCen:
	    if(gsSelectionMark_int == 1)
            snapPoints.append(m_ptStart);
        else if(gsSelectionMark_int == 2)
		    snapPoints.append(m_ptEnd);
        else
		    snapPoints.append(m_ptStart + (m_ptEnd - m_ptStart) / 2.0);
		break;
	case AcDb::kOsModeQuad:
	    for(i = 0; i < stdIdxLen____2; i++)
        {
            snapPoints.append(pArray[stdIdx[i * 2]]);
            snapPoints.append(pArray[stdIdx[i * 2] + actPrecision__1]);
	    }
        break;
    case AcDb::kOsModeNode:
		break;
    case AcDb::kOsModeIns:
		snapPoints.append(m_ptStart);
		break;
    case AcDb::kOsModePerp:
		{
            AcGeLine3d line;
            AcGeVector3d vec;
            AcGePoint3d pt;
            if(gsSelectionMark_int == 1)
            {
                AcGeCircArc3d cir(m_ptStart, vect, m_dDiameter1 / 2.0);
                pt = cir.closestPointTo(lastPoint);
                snapPoints.append(pt);
            }
            else if(gsSelectionMark_int == 2)
            {
                AcGeCircArc3d cir(m_ptEnd, vect, m_dDiameter2 / 2.0);
                pt = cir.closestPointTo(lastPoint);
                snapPoints.append(pt);
            }
			//重新定义对象垂直正交点的捕捉方式,同时满足实体模型和线框模型的捕捉 
			//modified by szw 2009.11.18 : begin
            else if(gsSelectionMark_int == 3)
            {
				for(int i = 0; i < stdIdxLen - 1; ++i)
				{
					vec = pArray[stdIdx[i]] - pArray[stdIdx[i] + actPrecision__1];
					line.set(pArray[stdIdx[i]], vec);
					pt = line.closestPointTo(lastPoint);
					snapPoints.append(pt);
				}
            }
			//modified by szw 2009.11.18 : end
        }
		break;
    case AcDb::kOsModeTan:
		break;
    case AcDb::kOsModeNear:
        {
            AcGePoint3d pt;
            AcGeCircArc3d cir;
            //下底面
            if(gsSelectionMark_int == 1)
            {
                cir.set(m_ptStart, vect, m_dDiameter1 / 2.0);
                pt = cir.projClosestPointTo(pickPoint, viewDir);
                snapPoints.append(pt);
            }
            //上底面
            else if(gsSelectionMark_int == 2)
            {
                cir.set(m_ptEnd, vect, m_dDiameter2 / 2.0);
                pt = cir.projClosestPointTo(pickPoint, viewDir);
                snapPoints.append(pt);
            }
            //棱边
			//重新定义对象垂直正交点的捕捉方式,同时满足实体模型和线框模型的捕捉 
			//modified by szw 2009.11.18 : begin
            else if(gsSelectionMark_int == 3)
            {
				AcGeLineSeg3d lnsg;
				AcGePoint3d p1,p2;
				for(int i = 0; i < stdIdxLen - 1; ++i)
				{
					p1 = pArray[stdIdx[i]];
					p2 = pArray[stdIdx[i] + actPrecision__1];
					lnsg.set(p1, p2);
// 					lnsg.set(pArray[stdIdx[i]], pArray[stdIdx[i] + actPrecision__1]);
					pt = lnsg.projClosestPointTo(pickPoint, viewDir);
					snapPoints.append(pt);

				}
            }
			//modified by szw 2009.11.18 : end
        }
        break;
    default:
        break;
    }

  return Acad::eOk;
}