bool AppController::_loadFile(const QString& path) { if ( !path.endsWith(".dat") ) return false; QFile file(path); file.open(QFile::ReadOnly); QDataStream stream(&file); while(m_LineController.count() > 0) model_removeLastLine(); int count; stream >> count; qreal x1, y1, x2, y2; for(int i=0; i<count; ++i) { stream >> x1 >> y1 >> x2 >> y2; QLineF line0(x1, y1, x2, y2); stream >> x1 >> y1 >> x2 >> y2; QLineF line1(x1, y1, x2, y2); model_addLine(line0, line1); } stream >> m_Img0 >> m_Img1; m_Scene0->setPixmap(m_Img0); m_Scene1->setPixmap(m_Img1); return true; }
dFloat dPolygonRayCast (const dVector& l0, const dVector& l1, int indexCount, const dFloat* const vertex, int strideInBytes, const int* const indices) { int stride = strideInBytes / sizeof (dFloat); dBigVector line0 (l0); dBigVector line1(l1); dBigVector segment (line1 - line0); dBigVector normal (dPolygonNormal (indexCount, vertex, strideInBytes, indices)); double den = normal % segment; if (dAbs(den) < 1.0e-6) { return 1.2f; } double sign = (den < 0.0f) ? 1.0f : -1.0f; int index = indices[indexCount - 1] * stride; dBigVector v0 (vertex[index], vertex[index + 1], vertex[index + 2], 0.0f); dBigVector p0v0 (v0 - line0); for (int i = 0; i < indexCount; i ++) { index = indices[i] * stride; dBigVector v1 (vertex[index], vertex[index + 1], vertex[index + 2], 0.0f); dBigVector p0v1 (v1 - line0); double alpha = sign * ((p0v1 * p0v0) % segment); if (alpha < 1.0e-3f) { return 1.2f; } p0v0 = p0v1; } double t = - ((line0 - v0) % normal) / den; if ((t < 0.0f) || (t > 1.0f)) { return 1.2f; } return dFloat (t); }
LocationPtr ParserBase::getLocation() const { LocationPtr location(new Location()); location->file = file(); location->line0 = line0(); location->char0 = char0(); location->line1 = line1(); location->char1 = char1(); return location; }
LocationPtr ParserBase::getLocation() const { auto location = std::make_shared<Location>(); location->file = file(); location->line0 = line0(); location->char0 = char0(); location->line1 = line1(); location->char1 = char1(); location->cursor = cursor(); return location; }
bool pointInTriangle(QPointF point, const Triangle &triangle) { QPointF a = triangle[0], b = triangle[1], c = triangle[2]; if (point == a || point == b || point == c) return true; QLineF line0(point, a), line1(point, b), line2(point, c); qreal angle0 = line0.angleTo(line1); angle0 = NORMALIZE_ANGLE(angle0); qreal angle1 = line1.angleTo(line2); angle1 = NORMALIZE_ANGLE(angle1); qreal angle2 = line2.angleTo(line0); angle2 = NORMALIZE_ANGLE(angle2); return qAbs(angle0 + angle1 + angle2 - 360) < EPS; }
Circle Poly::bs_getBCircle() const { int id = getObtuseCorner(); if(id >= 0) { // 鈍角を持っていれば直径を使う const Vec2 &v0 = point[spn::CndAdd(id-1, 3)], &v1 = point[spn::CndSub(id+1, 3)]; return Circle((v0+v1)*0.5f, v0.distance(v1)); } else { // なければ3点の外接円 Line line0((point[1]+point[0]) * 0.5f, (point[1]-point[0]) * cs_mRot90[0]), line1((point[2]+point[0]) * 0.5f, (point[2]-point[0]) * cs_mRot90[0]); auto vp = line0.nearest(line1); return Circle(vp.first, vp.first.distance(point[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"); }
/** *create circle inscribled in a triangle * *Author: Dongxu Li */ bool RS_Circle::createInscribe(const RS_Vector& coord, const std::vector<RS_Line*>& lines){ if(lines.size()<3) return false; std::vector<RS_Line*> tri(lines); RS_VectorSolutions sol=RS_Information::getIntersectionLineLine(tri[0],tri[1]); if(sol.getNumber() == 0 ) {//move parallel to opposite std::swap(tri[1],tri[2]); sol=RS_Information::getIntersectionLineLine(tri[0],tri[1]); } if(sol.getNumber() == 0 ) return false; RS_Vector vp0(sol.get(0)); sol=RS_Information::getIntersectionLineLine(tri[2],tri[1]); if(sol.getNumber() == 0 ) return false; RS_Vector vp1(sol.get(0)); RS_Vector dvp(vp1-vp0); double a(dvp.squared()); if( a< RS_TOLERANCE2) return false; //three lines share a common intersecting point RS_Vector vp(coord - vp0); vp -= dvp*(RS_Vector::dotP(dvp,vp)/a); //normal component RS_Vector vl0(tri[0]->getEndpoint() - tri[0]->getStartpoint()); a=dvp.angle(); double angle0(0.5*(vl0.angle() + a)); if( RS_Vector::dotP(vp,vl0) <0.) { angle0 += 0.5*M_PI; } RS_Line line0(vp0, vp0+RS_Vector(angle0));//first bisecting line vl0=(tri[2]->getEndpoint() - tri[2]->getStartpoint()); angle0=0.5*(vl0.angle() + a+M_PI); if( RS_Vector::dotP(vp,vl0) <0.) { angle0 += 0.5*M_PI; } RS_Line line1(vp1, vp1+RS_Vector(angle0));//second bisection line sol=RS_Information::getIntersectionLineLine(&line0,&line1); if(sol.getNumber() == 0 ) return false; bool ret=createFromCR(sol.get(0),tri[1]->getDistanceToPoint(sol.get(0))); if(!ret) return false; for(auto p: lines){ if(! p->isTangent(data)) return false; } return true; }
// build root file void EXOnator::makeTables(string bed_file,string conf_file) { string files[] = {"T_dup.txt","N_dup.txt"}; char buffer[5000]; string chrom,gene,sid; int start,end; double vals[1000]; for (int i = 0;i < 2;i++) { TFile iroot(_root_file.c_str(),"update"); TTree tree(files[i].substr(0,5).c_str(),files[i].substr(0,5).c_str()); tree.Branch("chrom",&chrom); tree.Branch("start",&start,"start/I"); tree.Branch("end", &end, "end/I"); tree.Branch("gene", &gene); ifstream fin(files[i].c_str()); fin.getline(buffer,5000); istringstream line0(buffer); line0>>sid>>sid>>sid>>sid; double *address = vals; while (line0>>sid) tree.Branch(sid.c_str(),address++,(sid + "/D").c_str()); while (fin.good()) { fin.getline(buffer,5000); istringstream line(buffer); line>>chrom>>start>>end>>gene; address = vals; while (line>>(*address)) address++; tree.Fill(); } fin.close(); tree.Write("",TObject::kOverwrite); iroot.Close(); } }
/* 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(); }