QList<RVector> RShape::getIntersectionPointsCE(const RCircle& circle1, const REllipse& ellipse2) { QList<RVector> res; REllipse ellipse1( circle1.getCenter(), RVector(circle1.getRadius(),0.), 1.0, 0.0, 2.0*M_PI, false); return getIntersectionPointsEE(ellipse1,ellipse2); }
void binShiftSchem(){ //set-up gROOT->Macro("init.C"); setStyle(); //make the plot TCanvas *cBinShift = new TCanvas("cBinShift", "cBinShift", 1000, 500); cBinShift->Divide(2,1); cBinShift->Draw(); cBinShift->cd(1); histo1(); box1(); ellipse1(); cBinShift->cd(2); histo2(); box2(); ellipse2(); }
//********************************************************************************************************** void CBCGPLinearGaugeImpl::OnDrawTickMark(CBCGPGraphicsManager* pGM, const CBCGPPoint& ptFrom, const CBCGPPoint& ptTo, CBCGPGaugeScaleObject::BCGP_TICKMARK_STYLE style, BOOL bMajor, double dblVal, int nScale, const CBCGPBrush& brFillIn, const CBCGPBrush& brOutlineIn) { ASSERT_VALID(pGM); CBCGPGaugeScaleObject* pScale = GetScale(nScale); if (pScale == NULL) { ASSERT(FALSE); return; } const double scaleRatio = GetScaleRatioMid(); const double dblSize = (bMajor ? pScale->m_dblMajorTickMarkSize : pScale->m_dblMinorTickMarkSize) * scaleRatio; const CBCGPGaugeColoredRangeObject* pRange = GetColoredRangeByValue(dblVal, nScale, BCGP_GAUGE_RANGE_TICKMARK_COLOR); const CBCGPBrush& brFill = (pRange != NULL && !pRange->m_brTickMarkFill.IsEmpty()) ? pRange->m_brTickMarkFill : (brFillIn.IsEmpty() ? m_Colors.m_brTickMarkFill : brFillIn); const CBCGPBrush& brOutline = (pRange != NULL && !pRange->m_brTickMarkOutline.IsEmpty()) ? pRange->m_brTickMarkOutline : (brOutlineIn.IsEmpty() ? m_Colors.m_brTickMarkOutline : brOutlineIn); switch (style) { case CBCGPGaugeScaleObject::BCGP_TICKMARK_LINE: pGM->DrawLine(ptFrom, ptTo, brOutline, scaleRatio); break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE: case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE_INV: case CBCGPGaugeScaleObject::BCGP_TICKMARK_BOX: { CBCGPPointsArray arPoints; const double dblWidth = (style == CBCGPGaugeScaleObject::BCGP_TICKMARK_BOX) ? (dblSize / 4.) : (bMajor ? (dblSize * 2. / 3.) : (dblSize / 2.)); const double dx = m_bIsVertical ? dblSize : max(dblWidth * .5, 3); const double dy = m_bIsVertical ? max(dblWidth * .5, 3) : dblSize; double x = ptTo.x; double y = ptTo.y; switch (style) { case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y + dy)); arPoints.Add(CBCGPPoint(x, y)); } else { arPoints.Add(CBCGPPoint(x + dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x, y)); } break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_TRIANGLE_INV: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x, y - dy)); arPoints.Add(CBCGPPoint(x, y + dy)); arPoints.Add(CBCGPPoint(x - dx, y)); } else { arPoints.Add(CBCGPPoint(x + dx, y)); arPoints.Add(CBCGPPoint(x - dx, y)); arPoints.Add(CBCGPPoint(x, y - dy)); } break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_BOX: if (m_bIsVertical) { arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y + dy)); arPoints.Add(CBCGPPoint(x, y + dy)); arPoints.Add(CBCGPPoint(x, y - dy)); } else { arPoints.Add(CBCGPPoint(x + dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y - dy)); arPoints.Add(CBCGPPoint(x - dx, y)); arPoints.Add(CBCGPPoint(x + dx, y)); } break; } CBCGPPolygonGeometry rgn(arPoints); pGM->FillGeometry(rgn, brFill); pGM->DrawGeometry(rgn, brOutline, scaleRatio); } break; case CBCGPGaugeScaleObject::BCGP_TICKMARK_CIRCLE: { CBCGPPoint ptCenter( .5 * (ptFrom.x + ptTo.x), .5 * (ptFrom.y + ptTo.y)); const double dblRadius = bMajor ? (dblSize / 2.) : (dblSize / 4.); CBCGPEllipse ellipse(ptCenter, dblRadius, dblRadius); pGM->FillEllipse(ellipse, brFill); pGM->DrawEllipse(ellipse, brOutline, scaleRatio); if (scaleRatio == 1.0 && !pGM->IsSupported(BCGP_GRAPHICS_MANAGER_ANTIALIAS)) { CBCGPEllipse ellipse1(ptCenter, dblRadius - 1., dblRadius - 1.); pGM->DrawEllipse(ellipse1, brOutline); } } break; } }
extern "C" void rt_ehy_brep(ON_Brep **b, const struct rt_db_internal *ip, const struct bn_tol *) { struct rt_ehy_internal *eip; RT_CK_DB_INTERNAL(ip); eip = (struct rt_ehy_internal *)ip->idb_ptr; RT_EHY_CK_MAGIC(eip); // Check the parameters if (!NEAR_ZERO(VDOT(eip->ehy_Au, eip->ehy_H), RT_DOT_TOL)) { bu_log("rt_ehy_brep: Au and H are not perpendicular!\n"); return; } if (!NEAR_EQUAL(MAGNITUDE(eip->ehy_Au), 1.0, RT_LEN_TOL)) { bu_log("rt_ehy_brep: Au not a unit vector!\n"); return; } if (MAGNITUDE(eip->ehy_H) < RT_LEN_TOL || eip->ehy_c < RT_LEN_TOL || eip->ehy_r1 < RT_LEN_TOL || eip->ehy_r2 < RT_LEN_TOL) { bu_log("rt_ehy_brep: not all dimensions positive!\n"); return; } if (eip->ehy_r2 > eip->ehy_r1) { bu_log("rt_ehy_brep: semi-minor axis cannot be longer than semi-major axis!\n"); return; } point_t p1_origin; ON_3dPoint plane1_origin, plane2_origin; ON_3dVector plane_x_dir, plane_y_dir; // First, find plane in 3 space corresponding to the bottom face of the EPA. vect_t x_dir, y_dir; VMOVE(x_dir, eip->ehy_Au); VCROSS(y_dir, eip->ehy_Au, eip->ehy_H); VUNITIZE(y_dir); VMOVE(p1_origin, eip->ehy_V); plane1_origin = ON_3dPoint(p1_origin); plane_x_dir = ON_3dVector(x_dir); plane_y_dir = ON_3dVector(y_dir); const ON_Plane ehy_bottom_plane(plane1_origin, plane_x_dir, plane_y_dir); // Next, create an ellipse in the plane corresponding to the edge of the ehy. ON_Ellipse ellipse1(ehy_bottom_plane, eip->ehy_r1, eip->ehy_r2); ON_NurbsCurve* ellcurve1 = ON_NurbsCurve::New(); ellipse1.GetNurbForm((*ellcurve1)); ellcurve1->SetDomain(0.0, 1.0); // Generate the bottom cap ON_SimpleArray<ON_Curve*> boundary; boundary.Append(ON_Curve::Cast(ellcurve1)); ON_PlaneSurface* bp = new ON_PlaneSurface(); bp->m_plane = ehy_bottom_plane; bp->SetDomain(0, -100.0, 100.0); bp->SetDomain(1, -100.0, 100.0); bp->SetExtents(0, bp->Domain(0)); bp->SetExtents(1, bp->Domain(1)); (*b)->m_S.Append(bp); const int bsi = (*b)->m_S.Count() - 1; ON_BrepFace& bface = (*b)->NewFace(bsi); (*b)->NewPlanarFaceLoop(bface.m_face_index, ON_BrepLoop::outer, boundary, true); const ON_BrepLoop* bloop = (*b)->m_L.Last(); bp->SetDomain(0, bloop->m_pbox.m_min.x, bloop->m_pbox.m_max.x); bp->SetDomain(1, bloop->m_pbox.m_min.y, bloop->m_pbox.m_max.y); bp->SetExtents(0, bp->Domain(0)); bp->SetExtents(1, bp->Domain(1)); (*b)->SetTrimIsoFlags(bface); delete ellcurve1; // Now, the hard part. Need an elliptical hyperbolic NURBS surface // First step is to create a nurbs curve. double intercept_calc = (eip->ehy_c)*(eip->ehy_c)/(MAGNITUDE(eip->ehy_H) + eip->ehy_c); double intercept_dist = MAGNITUDE(eip->ehy_H) + eip->ehy_c - intercept_calc; double intercept_length = intercept_dist - MAGNITUDE(eip->ehy_H); double MX = MAGNITUDE(eip->ehy_H); double MP = MX + intercept_length; double w = (MX/MP)/(1-MX/MP); point_t ep1, ep2, ep3; VSET(ep1, -eip->ehy_r1, 0, 0); VSET(ep2, 0, 0, w*intercept_dist); VSET(ep3, eip->ehy_r1, 0, 0); ON_3dPoint onp1 = ON_3dPoint(ep1); ON_3dPoint onp2 = ON_3dPoint(ep2); ON_3dPoint onp3 = ON_3dPoint(ep3); ON_3dPointArray cpts(3); cpts.Append(onp1); cpts.Append(onp2); cpts.Append(onp3); ON_BezierCurve *bcurve = new ON_BezierCurve(cpts); bcurve->MakeRational(); bcurve->SetWeight(1, w); ON_NurbsCurve* tnurbscurve = ON_NurbsCurve::New(); bcurve->GetNurbForm(*tnurbscurve); ON_NurbsCurve* hypbnurbscurve = ON_NurbsCurve::New(); const ON_Interval subinterval = ON_Interval(0, 0.5); tnurbscurve->GetNurbForm(*hypbnurbscurve, 0.0, &subinterval); // Next, rotate that curve around the height vector. point_t revpoint1, revpoint2; VSET(revpoint1, 0, 0, 0); VSET(revpoint2, 0, 0, MX); ON_3dPoint rpnt1 = ON_3dPoint(revpoint1); ON_3dPoint rpnt2 = ON_3dPoint(revpoint2); ON_Line revaxis = ON_Line(rpnt1, rpnt2); ON_RevSurface* hyp_surf = ON_RevSurface::New(); hyp_surf->m_curve = hypbnurbscurve; hyp_surf->m_axis = revaxis; hyp_surf->m_angle = ON_Interval(0, 2*ON_PI); // Get the NURBS form of the surface ON_NurbsSurface *ehycurvedsurf = ON_NurbsSurface::New(); hyp_surf->GetNurbForm(*ehycurvedsurf, 0.0); delete hyp_surf; delete tnurbscurve; delete bcurve; // Transformations for (int i = 0; i < ehycurvedsurf->CVCount(0); i++) { for (int j = 0; j < ehycurvedsurf->CVCount(1); j++) { point_t cvpt; ON_4dPoint ctrlpt; ehycurvedsurf->GetCV(i, j, ctrlpt); // Scale the control points of the // resulting surface to map to the shorter axis. VSET(cvpt, ctrlpt.x, ctrlpt.y * eip->ehy_r2/eip->ehy_r1, ctrlpt.z); // Rotate according to the directions of Au and H vect_t Hu; mat_t R; point_t new_cvpt; VSCALE(Hu, eip->ehy_H, 1/MAGNITUDE(eip->ehy_H)); MAT_IDN(R); VMOVE(&R[0], eip->ehy_Au); VMOVE(&R[4], y_dir); VMOVE(&R[8], Hu); VEC3X3MAT(new_cvpt, cvpt, R); VMOVE(cvpt, new_cvpt); // Translate according to V vect_t scale_v; VSCALE(scale_v, eip->ehy_V, ctrlpt.w); VADD2(cvpt, cvpt, scale_v); ON_4dPoint newpt = ON_4dPoint(cvpt[0], cvpt[1], cvpt[2], ctrlpt.w); ehycurvedsurf->SetCV(i, j, newpt); } } (*b)->m_S.Append(ehycurvedsurf); int surfindex = (*b)->m_S.Count(); ON_BrepFace& face = (*b)->NewFace(surfindex - 1); (*b)->FlipFace(face); int faceindex = (*b)->m_F.Count(); (*b)->NewOuterLoop(faceindex-1); }