本文整理汇总了C#中Region.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Region.Intersect方法的具体用法?C# Region.Intersect怎么用?C# Region.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Region
的用法示例。
在下文中一共展示了Region.Intersect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsFit
public bool IsFit(Point[] points)
{
// Note: rigorously calculating distance(point,ellipse) is very hard...
// overlay the regions and compare the areas, for now.
using (GraphicsPath polygp = new GraphicsPath())
using (GraphicsPath elligp = new GraphicsPath())
using (Matrix m = new Matrix())
{
// Set up gp for stroke.
polygp.AddPolygon(points);
// Set up gp for ellipse.
elligp.AddEllipse((float)-mj,(float)-mn,(float)mj*2,(float)mn*2);
m.Translate((float)cx,(float)cy);
m.Rotate((float)th);
elligp.Transform(m);
// Prepare regions for area-calculation.
using (Region xor = new Region(elligp))
using (Region isc = new Region(elligp))
{
xor.Xor(polygp);
isc.Intersect(polygp);
float badarea = Geometry.CalculateArea(xor);
float iscarea = Geometry.CalculateArea(isc);
float ratio = iscarea/badarea;
//heuristic: 10.0 seems about right.
return (ratio > 10f);
}
}
}
示例2: Main
public static void Main ()
{
Bitmap bmp = new Bitmap (600, 300);
Graphics dc = Graphics.FromImage (bmp);
Font fnt = new Font ("Arial", 8);
Font fnttitle = new Font ("Arial", 8, FontStyle.Underline);
Matrix matrix = new Matrix ();
GraphicsPath patha = new GraphicsPath ();
GraphicsPath pathb = new GraphicsPath ();
Pen redPen = new Pen (Color.Red, 2);
Region rgn1;
Region rgn2;
int x = 0;
SolidBrush whiteBrush = new SolidBrush (Color.White);
dc.DrawString ("Region samples using GraphicsPath", fnttitle, whiteBrush, 5, 5);
/* First*/
patha.AddLine (60, 40, 90, 90);
patha.AddLine (90, 90, 10, 90);
patha.AddLine (10, 90, 60, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse(30, 55, 60, 60);
dc.DrawPath(redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Complement (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Complement (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 10, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Second*/
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
patha.AddLine (90+x, 90, 10+x, 90);
patha.AddLine (10+x, 90, 60+x, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse (30+x, 55, 60, 60);
dc.DrawPath(redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Exclude (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Exclude (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 140, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Third*/
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
patha.AddLine (90+x, 90, 10+x, 90);
patha.AddLine (10+x, 90, 60+x, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse (30+x, 55, 60, 60);
dc.DrawPath (redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Intersect (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Intersect (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 270, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Four*/
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
patha.AddLine (90+x, 90, 10+x, 90);
patha.AddLine (10+x, 90, 60+x, 40);
dc.DrawPath (redPen, patha);
pathb.AddEllipse (30+x, 55, 60, 60);
dc.DrawPath (redPen, pathb);
rgn1 = new Region (patha);
rgn2 = new Region (pathb);
rgn1.Xor (rgn2);
dc.FillRegion(Brushes.Blue, rgn1);
dc.DrawString ("Xor (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 380, 140);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
x += 110;
/* Fifth */
patha.Reset ();
pathb.Reset ();
patha.AddLine (60+x, 40, 90+x, 90);
//.........这里部分代码省略.........
示例3: Tick
//.........这里部分代码省略.........
// If body still at rest, don't move it.
if (body.initiallyAtRest)
continue;
// Add it up, and move the bodies. Note, we're just doing simple
// Euler integration, for now. If integration error proves to be a
// problem, Runge-Kutta or Improved Euler could be implemented here,
// for better results (at the expense of a little performance).
body.Vx += dt * body.totalForce.DX/body.Mass; // isu/sec
body.Vy += dt * body.totalForce.DY/body.Mass; // isu/sec
body.Va += dt * body.totalAngularForce/body.I; // radians/sec
int dx=0,dy=0; float da=0f;
dx = MathEx.Round(dt * body.Vx);
dy = MathEx.Round(dt * body.Vy);
da = (float)Geometry.Rad2Deg(dt * body.Va);
body.Move(dx,dy,da);
// Move force mechanisms
foreach (MechanismBase mech in doc.GetMechanismsForBody(body))
{
if (mech is ForceMechanismBase)
mech.Move(dx,dy,da);
}
}
// Apply a method to stabilize rods, pin joints, and ropes.
StabilizeBindingMechanisms();
// Everything works better when there are no overlaps, so physically
// separate any objects that are intersecting.
SeparateIntersectingObjects();
// Look for collisions, apply impulses.
collisions.Clear();
foreach (RigidBodyBase body1 in doc.Bodies)
foreach (RigidBodyBase body2 in doc.Bodies)
{
if (Object.ReferenceEquals(body1,body2)) continue;
if (body1.anchored && body2.anchored) continue;
Point contactPoint;
PointF normal;
if (!FindIntersection(body1, body2, out contactPoint, out normal)) continue;
using (Graphics g = wnd.CreateGraphics())
using (Region contactrgn = RigidBodyBase.GetOverlap(body1,body2))
{
if (contactrgn.IsEmpty(g)) continue;
// We've got a hit; but make sure it's waxing not waning.
int dx1=0,dy1=0,dx2=0,dy2=0; float da1=0f,da2=0f;
dx1 = MathEx.Round(dt * body1.Vx);
dy1 = MathEx.Round(dt * body1.Vy);
da1 = (float)Geometry.Rad2Deg(dt * body1.Va);
dx2 = MathEx.Round(dt * body2.Vx);
dy2 = MathEx.Round(dt * body2.Vy);
da2 = (float)Geometry.Rad2Deg(dt * body2.Va);
using (Matrix m1 = new Matrix())
using (Matrix m2 = new Matrix())
using (Region rgn = new Region())
示例4: Main
public static void Main ()
{
Bitmap bmp = new Bitmap (600, 800);
Graphics dc = Graphics.FromImage (bmp);
Font fnt = new Font ("Arial", 8);
Font fnttitle = new Font("Arial", 8, FontStyle.Underline);
Matrix matrix = new Matrix ();
int x = 0;
Rectangle rect1, rect2, rect3, rect4;
Region rgn1, rgn2, rgn3, rgn4;
bool complement = true, exclude = true, union = true, xor = true, intersect = true;
SolidBrush whiteBrush = new SolidBrush (Color.White);
dc.DrawString ("Region samples using two Rectangle classes", fnttitle, whiteBrush, 5, 5);
/* First */
if (complement) {
rect1 = new Rectangle (20, 30, 60, 80);
rect2 = new Rectangle (50, 40, 60, 80);
rgn1 = new Region (rect1);
rgn2 = new Region (rect2);
dc.DrawRectangle (Pens.Green, rect1);
dc.DrawRectangle (Pens.Red, rect2);
rgn1.Complement (rgn2);
dc.FillRegion (Brushes.Blue, rgn1);
dc.DrawString ("Complement (" + rgn1.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 10, 130);
dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
DumpRegion (rgn1);
}
/* Second */
if (exclude) {
rect3 = new Rectangle (130, 30, 60, 80);
rect4 = new Rectangle (170, 40, 60, 80);
rgn3 = new Region (rect3);
rgn4 = new Region (rect4);
dc.DrawRectangle (Pens.Green, rect3);
dc.DrawRectangle (Pens.Red, rect4);
rgn3.Exclude (rgn4);
dc.FillRegion (Brushes.Blue, rgn3);
dc.DrawString ("Exclude (" + rgn3.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 130, 130);
dc.DrawRectangles (Pens.Yellow, rgn3.GetRegionScans (matrix));
DumpRegion (rgn3);
}
/* Third */
if (intersect) {
Rectangle rect5 = new Rectangle (260, 30, 60, 80);
Rectangle rect6 = new Rectangle (290, 40, 60, 80);
Region rgn5 = new Region (rect5);
Region rgn6 = new Region (rect6);
dc.DrawRectangle (Pens.Green, rect5);
dc.DrawRectangle (Pens.Red, rect6);
rgn5.Intersect (rgn6);
dc.FillRegion (Brushes.Blue, rgn5);
dc.DrawString ("Intersect (" + rgn5.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 270, 130);
dc.DrawRectangles (Pens.Yellow, rgn5.GetRegionScans (matrix));
DumpRegion (rgn5);
}
/* Four */
if (xor) {
Rectangle rect7 = new Rectangle (380, 30, 60, 80);
Rectangle rect8 = new Rectangle (410, 40, 60, 80);
Region rgn7 = new Region (rect7);
Region rgn8 = new Region (rect8);
dc.DrawRectangle (Pens.Green, rect7);
dc.DrawRectangle (Pens.Red, rect8);
rgn7.Xor (rgn8);
dc.FillRegion (Brushes.Blue, rgn7);
dc.DrawString ("Xor (" + rgn7.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 400, 130);
dc.DrawRectangles (Pens.Yellow, rgn7.GetRegionScans (matrix));
DumpRegion (rgn7);
}
/* Fifht */
if (union) {
Rectangle rect9 = new Rectangle (500, 30, 60, 80);
Rectangle rect10 = new Rectangle (520, 40, 60, 80);
Region rgn9 = new Region(rect9);
Region rgn10 = new Region(rect10);
dc.DrawRectangle (Pens.Green, rect9);
dc.DrawRectangle (Pens.Red, rect10);
rgn9.Union(rgn10);
dc.FillRegion (Brushes.Blue, rgn9);
dc.DrawString ("Union (" + rgn9.GetRegionScans (matrix).Length +")", fnt, whiteBrush, 530, 130);
dc.DrawRectangles (Pens.Yellow, rgn9.GetRegionScans (matrix));
DumpRegion (rgn9);
}
dc.DrawString ("Region samples using three Rectangle class", fnttitle, whiteBrush, 5, 155);
/* First */
x = 0;
if (complement) {
rect1 = new Rectangle (20+x, 180, 40, 50);
//.........这里部分代码省略.........