本文整理汇总了C#中Region.GetRegionScans方法的典型用法代码示例。如果您正苦于以下问题:C# Region.GetRegionScans方法的具体用法?C# Region.GetRegionScans怎么用?C# Region.GetRegionScans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Region
的用法示例。
在下文中一共展示了Region.GetRegionScans方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DumpRegion
public static void DumpRegion (Region rgn)
{
Matrix matrix = new Matrix ();
RectangleF [] rects = rgn.GetRegionScans (matrix);
for (int i = 0; i < rects.Length; i++)
Console.WriteLine ( rects[i]);
}
示例2: CalculateArea
public static float CalculateArea(Region region)
{
using (Matrix identity = new Matrix())
{
RectangleF[] rects = region.GetRegionScans(identity);
float sumA = 0f;
foreach (RectangleF rect in rects)
sumA += (rect.Width*rect.Height);
return sumA;
}
}
示例3: CenterOfGravity
public static Point CenterOfGravity(Region region)
{
using (Matrix identity = new Matrix())
{
RectangleF[] rects = region.GetRegionScans(identity);
float sumX = 0f;
float sumY = 0f;
float area = 0f;
foreach (RectangleF rect in rects)
{
sumX += ((rect.Left+rect.Right)/2f) * (rect.Width*rect.Height);
sumY += ((rect.Top+rect.Bottom)/2f) * (rect.Width*rect.Height);
area += (rect.Width*rect.Height);
}
int avgX = MathEx.Round(sumX/area);
int avgY = MathEx.Round(sumY/area);
return new Point(avgX,avgY);
}
}
示例4: CalculateMoment
public static double CalculateMoment(Region region)
{
Point cg = CenterOfGravity(region);
using (Matrix identity = new Matrix())
{
RectangleF[] rects = region.GetRegionScans(identity);
double moment = 0.0;
foreach (RectangleF rect in rects)
{
// Sum I0+md²; I0 = m/12*(W²+H²)
Point cp = Geometry.Midpoint(Geometry.Round(rect));
double m = (rect.Width/1000f*rect.Height/1000f); // assume 1g/cm²
double i0 = m/12.0 * (MathEx.Square(rect.Width/1000f)+MathEx.Square(rect.Height/1000f));
moment += i0 + m * MathEx.Square(Geometry.DistanceBetween(cp,cg)/1000f);
}
return moment;
}
}
示例5: 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);
//.........这里部分代码省略.........
示例6: 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);
//.........这里部分代码省略.........
示例7: RegionCentroid
private PointF RegionCentroid(Region region, Matrix transform)
{
float mx = 0;
float my = 0;
float total_weight = 0;
foreach (RectangleF rect in region.GetRegionScans(transform))
{
float rect_weight = rect.Width * rect.Height;
mx += rect_weight * (rect.Left + rect.Width / 2f);
my += rect_weight * (rect.Top + rect.Height / 2f);
total_weight += rect_weight;
}
return new PointF(mx / total_weight, my / total_weight);
}