本文整理汇总了C#中System.Drawing.Drawing2D.Matrix.RotateAt方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Drawing2D.Matrix.RotateAt方法的具体用法?C# System.Drawing.Drawing2D.Matrix.RotateAt怎么用?C# System.Drawing.Drawing2D.Matrix.RotateAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.Matrix
的用法示例。
在下文中一共展示了System.Drawing.Drawing2D.Matrix.RotateAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeMap
public static SharpMap.Map InitializeMap(float angle)
{
using (var ofn = new System.Windows.Forms.OpenFileDialog())
{
ofn.Filter = "All files|*.*";
ofn.FilterIndex = 0;
if (ofn.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var m = new SharpMap.Map();
var l = new SharpMap.Layers.GdiImageLayer(ofn.FileName);
m.Layers.Add(l);
m.ZoomToExtents();
var mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, m.WorldToImage(m.Center));
m.MapTransform = mat;
m.MaximumExtents = m.GetExtents();
m.EnforceMaximumExtents = true;
return m;
}
}
return null;
}
示例2: InitializeMap
public static SharpMap.Map InitializeMap(int angle, string[] filenames)
{
var map = new SharpMap.Map();
for (int i = 0; i < filenames.Length; i++)
map.Layers.Add(new SharpMap.Layers.GdalRasterLayer(System.IO.Path.GetFileName(filenames[i]), filenames[i]));
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
map.ZoomToExtents();
return map;
}
示例3: ToPoints
public List<Point> ToPoints(
float angle,
Rectangle rect)
{
// Graphics g = Graphics.FromImage(this.Image);
Graphics g = Graphics.FromHwnd(this.Handle);
List<Point> source_points = new List<Point>();
source_points.Add(new Point(rect.X, rect.Y));
source_points.Add(new Point(rect.X + rect.Width, rect.Y));
source_points.Add(new Point(rect.X +rect.Width, rect.Y + rect.Height));
source_points.Add(new Point(rect.X, rect.Y + rect.Height));
Point[] pts = source_points.ToArray();
Rectangle display_rect = GetPictureBoxZoomSize();
float x_ratio = (float)display_rect.Width / (float)this.Image.Width;
float y_ratio = (float)display_rect.Height / (float)this.Image.Height;
System.Drawing.Drawing2D.Matrix rotateMatrix =
new System.Drawing.Drawing2D.Matrix();
// Set the rotation angle and starting point for the text.
rotateMatrix.RotateAt(angle, new PointF(this.Image.Width / 2, this.Image.Height / 2));
//rotateMatrix.RotateAt(angle, new PointF(0, 0));
g.MultiplyTransform(rotateMatrix);
// g.ScaleTransform(x_ratio, y_ratio);
// g.ScaleTransform((float)1.1, (float)1.1);
// g.RotateTransform(angle);
g.TransformPoints(System.Drawing.Drawing2D.CoordinateSpace.World, System.Drawing.Drawing2D.CoordinateSpace.Device, pts);
return pts.ToList();
}
示例4: TestAffineTransform2D
public void TestAffineTransform2D()
{
//Setup some affine transformation
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix();
matrix.RotateAt(30, new System.Drawing.PointF(0, 0));
matrix.Translate(-20, -20, System.Drawing.Drawing2D.MatrixOrder.Append);
matrix.Shear(0.95f, -0.2f, System.Drawing.Drawing2D.MatrixOrder.Append);
//Create some random sample data
CreatingData cd = new CreatingData();
SharpMap.Data.FeatureDataTable fdt1 =
cd.CreatePointFeatureDataTableFromArrays(GetRandomOrdinates(80, -180, 180),
GetRandomOrdinates(80, -90, 90), null);
//Clone random sample data and apply affine transformation on it
SharpMap.Data.FeatureDataTable fdt2 = TransformedFeatureDataTable(matrix, fdt1);
//Get affine transformation with LeastSquaresTransform
SharpMap.Utilities.LeastSquaresTransform lst = new SharpMap.Utilities.LeastSquaresTransform();
//Add at least three corresponding points
lst.AddInputOutputPoint(
((SharpMap.Data.FeatureDataRow)fdt1.Rows[0]).Geometry as SharpMap.Geometries.Point,
((SharpMap.Data.FeatureDataRow)fdt2.Rows[0]).Geometry as SharpMap.Geometries.Point);
lst.AddInputOutputPoint(
((SharpMap.Data.FeatureDataRow)fdt1.Rows[39]).Geometry as SharpMap.Geometries.Point,
((SharpMap.Data.FeatureDataRow)fdt2.Rows[39]).Geometry as SharpMap.Geometries.Point);
lst.AddInputOutputPoint(
((SharpMap.Data.FeatureDataRow)fdt1.Rows[79]).Geometry as SharpMap.Geometries.Point,
((SharpMap.Data.FeatureDataRow)fdt2.Rows[79]).Geometry as SharpMap.Geometries.Point);
/*
//Get affine transformation calculates mean points to improve accuaracy
//Unfortunately the result is not very good, so, since I know better I manually set these
//mean points.
lst.SetMeanPoints(new SharpMap.Geometries.Point(0, 0),
new SharpMap.Geometries.Point(matrix.OffsetX, matrix.OffsetY));
*/
//Create Affine
AffineCoordinateTransformation2D at2 = new AffineCoordinateTransformation2D(lst.GetAffineTransformation());
//Create Map
SharpMap.Map map = new SharpMap.Map(new System.Drawing.Size(720, 360));
//Add not transformed layer
map.Layers.Add(new SharpMap.Layers.VectorLayer("L1",
new SharpMap.Data.Providers.GeometryFeatureProvider(fdt1)));
((SharpMap.Layers.VectorLayer) map.Layers[0]).Style.Symbol =
new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\flag.png");
//Add transformed layer
map.Layers.Add(new SharpMap.Layers.VectorLayer("L2",
new SharpMap.Data.Providers.GeometryFeatureProvider(fdt2)));
((SharpMap.Layers.VectorLayer) map.Layers[1]).Style.Symbol =
new System.Drawing.Bitmap(@"..\..\..\DemoWinForm\Resources\women.png");
//Render map
map.ZoomToExtents();
//Get map and save to file
var bmp = (System.Drawing.Bitmap)map.GetMap();
bmp.Save("affinetransform1.bmp");
//we want to reverse the previously applied transformation.
((SharpMap.Layers.VectorLayer) map.Layers[1]).CoordinateTransformation = (AffineCoordinateTransformation2D)at2.Inverse();
//Render map
map.ZoomToExtents();
//Get map and save to file
bmp = (System.Drawing.Bitmap)map.GetMap();
bmp.Save("affinetransform2.bmp");
//Hopefully women cover flags ;-).
}
示例5: rotatePoint
public void rotatePoint(PointF centerpoint, float angle, ref PointF dstpoint)
{
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, centerpoint);
PointF[] arraypoints = new PointF[1];
arraypoints[0] = dstpoint;
mat.TransformPoints(arraypoints);
dstpoint = arraypoints[0];
}
示例6: InitializeGeoTiff
private static SharpMap.Map InitializeGeoTiff(int index, float angle)
{
try
{
//Sample provided by Dan Brecht and Joel Wilson
var map = new SharpMap.Map();
map.BackColor = System.Drawing.Color.White;
const string relativePath = "GeoData/GeoTiff/";
SharpMap.Layers.GdalRasterLayer layer;
switch (index)
{
case 2:
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.tif");
layer.UseRotation = true;
map.Layers.Add(layer);
break;
case 3:
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "utm.jp2");
layer.UseRotation = true;
map.Layers.Add(layer);
break;
case 4:
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiff", relativePath + "world_raster_mod.tif");
layer.UseRotation = true;
map.Layers.Add(layer);
break;
default:
if (!System.IO.File.Exists(relativePath + "format01-image_a.tif"))
{
throw new System.Exception("Make sure the data is in the relative directory: " + relativePath);
}
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif");
map.Layers.Add(layer);
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif");
map.Layers.Add(layer);
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif");
map.Layers.Add(layer);
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif");
map.Layers.Add(layer);
SharpMap.Layers.VectorLayer shapeLayer;
if (!System.IO.File.Exists(relativePath + "outline.shp"))
{
throw new System.Exception("Make sure the data is in the relative directory: " + relativePath);
}
shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp"));
shapeLayer.Style.Fill = System.Drawing.Brushes.Transparent;
shapeLayer.Style.Outline = System.Drawing.Pens.Black;
shapeLayer.Style.EnableOutline = true;
shapeLayer.Style.Enabled = true;
map.Layers.Add(shapeLayer);
break;
}
map.ZoomToExtents();
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
if (_num > 5) _num = 1;
_gdalSampleDataset = "GeoTiff" + _num;
return map;
}
catch (System.TypeInitializationException ex)
{
if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.")
{
throw new System.Exception(
string.Format(
"The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
SharpMap.Layers.GdalRasterLayer.FWToolsVersion));
}
throw;
}
}
示例7: FindRelativeLocation
/// <summary>
/// Find location of PicBox relative to the Rovio.
/// </summary>
/// <param name="picBox">Picture box to check.</param>
/// <param name="rect">Rectangle of the picture box's object on screen</param>
/// <param name="distance">Distance to object</param>
/// <param name="multiplierOne">First multiplier to change X position by.</param>
/// <param name="multiplierTwo">Second multiplier to change X position by.</param>
private void FindRelativeLocation(PictureBox picBox, DRectangle rect, double distance, int multiplierOne, int multiplierTwo)
{
picBox.Location = new System.Drawing.Point(picBoxRovio.Location.X + rect.X + rect.Width, picBoxRovio.Location.Y - (int)(distance * 20 * 3));
double totalFOV = distance * 100 * 0.93;
double percentage = rect.X / (double)robot.cameraDimensions.X * 100;
double newX = percentage * (totalFOV / 100);
DPoint newPosition = new System.Drawing.Point(picBoxRovio.Location.X - ((int)totalFOV / 2) + (int)newX*2, picBox.Location.Y);
using (matrix = new System.Drawing.Drawing2D.Matrix())
{
matrix.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2)));
matrix.Translate((float)-newX + 30f, -(float)(distance * multiplierOne * multiplierTwo));
DPoint[] aPoints = { newPosition };
matrix.TransformPoints(aPoints);
picBox.Location = aPoints[0];
}
}
示例8: InitializeMap
internal static SharpMap.Map InitializeMap(float angle, string[] filenames)
{
var map = new SharpMap.Map();
try
{
foreach (var filename in filenames)
{
var connectionString = string.Format("Data Source={0}", filename);
foreach (var provider in SharpMap.Data.Providers.SpatiaLite.GetSpatialTables(connectionString))
{
map.Layers.Add(
new SharpMap.Layers.VectorLayer(
string.Format("{0} - {1}", provider.Table, provider.GeometryColumn), provider) { Style = LayerTools.GetRandomVectorStyle() });
}
}
if (map.Layers.Count > 0)
{
map.ZoomToExtents();
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
return map;
}
}
catch (System.Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
return null;
}
示例9: Carte_Paint
private void Carte_Paint(object sender, PaintEventArgs e)
{
int i;
double w, h;
//projet = ((Musliw.MusliW)(this.MdiParent)).projet;
Graphics page = e.Graphics;
//page.Clear(this.BackColor);
w = this.Width;
h = this.Height;
Pen stylo = new Pen(fen.stylo_couleur, (int)fen.epaisseur);
Font fonte = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold);
this.ForeColor = Color.Black;
Brush brosse =new SolidBrush(fen.brosse_couleur);
Brush brosse_texte = new SolidBrush(fen.couleur_texte);
double dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
double dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
double deltax,deltay,voldeltax,voldeltay;
double cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
double cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);
//MessageBox.Show(xl.ToString() + " " + yu.ToString());
PointF p1=new PointF();
PointF p2 = new PointF();
PointF p3 = new PointF();
PointF p4 = new PointF();
PointF p5 = new PointF();
PointF[] points = new PointF[4] ;
double angle=0,norme=0;
double sinx = 0, cosx = 1;
if (fen.volume_echelle < 1e-6f)
{
fen.volume_echelle = 1e-6f;
}
for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
{
norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
{
//page.DrawRectangle(stylo, 0f, 0f, 200, 200);
//MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
cosx = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
sinx = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
page.DrawLine(stylo, (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay), (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax),(float) (((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay),(float) (((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax));
p1.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay);
p1.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax);
p2.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay);
p2.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax);
p3.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay);
p3.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax);
p4.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay);
p4.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);
System.Drawing.Drawing2D.GraphicsPath epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
epaisseur.StartFigure();
points[0] = p1;
points[1] = p2;
points[2] = p3;
points[3] = p4;
epaisseur.AddPolygon(points);
epaisseur.CloseFigure();
//page.FillPath(brosse, epaisseur);
//page.FillPolygon(brosse, points);
//page.DrawPolygon(stylo,points);
epaisseur.Reset();
texte_epaisseur.StartFigure();
p5.X = 0.5f * (p3.X + p2.X);
p5.Y = 0.5f * (p3.Y + p2.Y);
texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, (float)fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
RectangleF encombrement = texte_epaisseur.GetBounds();
// texte_epaisseur.AddRectangle(encombrement);
//texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);
page.FillPolygon(brosse, points);
page.DrawPolygon(stylo, points);
if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
{
System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();
if (cosx >= 0 && sinx <= 0)
{
angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
rotation.RotateAt((float)angle, p5);
rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
texte_epaisseur.Transform(rotation);
trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
//.........这里部分代码省略.........
示例10: GetUpperCorner
private static PointF GetUpperCorner( float rotation, float left, float top, float width, float height )
{
// BUG 1006: Need to account for rotation when determining bounds
if( rotation != 0 ) {
PointF[] pts = new PointF[4];
pts[0] = new PointF( left, top );
pts[1] = new PointF( left, top + height );
pts[2] = new PointF( left + width, top );
pts[3] = new PointF( left + width, top + height );
// Rotate the points
System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
m.RotateAt( rotation, new PointF( left + width/2.0f, top + height/2.0f ) );
m.TransformPoints( pts );
return new PointF( Math.Min( Math.Min( Math.Min( pts[0].X, pts[1].X ), pts[2].X ), pts[3].X ),
Math.Min( Math.Min( Math.Min( pts[0].Y, pts[1].Y ), pts[2].Y ), pts[3].Y ) );
} else {
return new PointF( left, top );
}
}
示例11: mapPanel_Paint
//.........这里部分代码省略.........
PointF p = new PointF((center.X) - ThingDb.Things[oe.Name].ExtentX, (center.Y - (ThingDb.Things[oe.Name].ZSizeY)) - ThingDb.Things[oe.Name].ExtentX);
Pen rotatePen;
if (oe.Name.Contains("Amb"))
{
rotatePen = new Pen(Color.LightGray, 1);
}
else
rotatePen = new Pen(Color.Green, 1);
PointF point1 = new PointF(t.X, t.Y);
point1.Y += ThingDb.Things[oe.Name].ExtentX;
PointF point2 = new PointF(p.X, p.Y);
point2.Y += ThingDb.Things[oe.Name].ExtentX;
g.DrawLine(rotatePen, point1, point2);
point1.X += ThingDb.Things[oe.Name].ExtentX * 2;
point2.X += ThingDb.Things[oe.Name].ExtentX * 2;
g.DrawLine(rotatePen, point1, point2);
g.DrawEllipse(rotatePen, new RectangleF(t, new Size(2 * ThingDb.Things[oe.Name].ExtentX, 2 * ThingDb.Things[oe.Name].ExtentX)));
g.DrawEllipse(rotatePen, new RectangleF(p, new Size(2 * ThingDb.Things[oe.Name].ExtentX, 2 * ThingDb.Things[oe.Name].ExtentX)));
}
if (ThingDb.Things[oe.Name].ExtentType == "BOX")
{
Point t = new Point((int)(center.X - (ThingDb.Things[oe.Name].ExtentX / 2)), (int)(center.Y - (ThingDb.Things[oe.Name].ExtentY / 2)));
Point p = new Point((int)((center.X - (ThingDb.Things[oe.Name].ZSizeY / 2)) - (ThingDb.Things[oe.Name].ExtentX / 2)), (int)((center.Y - (ThingDb.Things[oe.Name].ZSizeY / 2)) - (ThingDb.Things[oe.Name].ExtentY / 2)));
using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix())
{
m.RotateAt(45, center);
g.Transform = m;
Pen rotatePen = new Pen(Color.Green, 1);
PointF point1 = new PointF(t.X, t.Y);
PointF point2 = new PointF(p.X, p.Y);
g.DrawLine(rotatePen, point1, point2);
point1 = new PointF(t.X, t.Y);
point2 = new PointF(p.X, p.Y);
point1.Y += ThingDb.Things[oe.Name].ExtentY;
point2.Y += ThingDb.Things[oe.Name].ExtentY;
g.DrawLine(rotatePen, point1, point2);
point1 = new PointF(t.X, t.Y);
point2 = new PointF(p.X, p.Y);
point1.X += ThingDb.Things[oe.Name].ExtentX;
point2.X += ThingDb.Things[oe.Name].ExtentX;
g.DrawLine(rotatePen, point1, point2);
point1 = new PointF(t.X, t.Y);
point2 = new PointF(p.X, p.Y);
point1.X += ThingDb.Things[oe.Name].ExtentX;
point2.X += ThingDb.Things[oe.Name].ExtentX;
point1.Y += ThingDb.Things[oe.Name].ExtentY;
point2.Y += ThingDb.Things[oe.Name].ExtentY;
g.DrawLine(rotatePen, point1, point2);
g.DrawRectangle(rotatePen, new Rectangle(t, new Size(ThingDb.Things[oe.Name].ExtentX, ThingDb.Things[oe.Name].ExtentY)));
g.DrawRectangle(rotatePen, new Rectangle(p, new Size(ThingDb.Things[oe.Name].ExtentX, ThingDb.Things[oe.Name].ExtentY)));
//g.ResetTransform();
g.ResetTransform();
}
示例12: Update
/// <summary>
/// Update function of map. Calls Bayes filtering and handles the rotation and translation of all map objects.
/// </summary>
private void Update(object sender, EventArgs e)
{
lock (robot.mapLock)
{
Bayes(true, preySensor, ref preyProbability);
Bayes(false, obstacleSensor, ref obstacleProbability);
bBayes = new Bitmap(bMap.Size.Width, bMap.Size.Height);
SetNewRovioPosition();
// Run AStar if there is a suitable destination and draw it on the map.
using (graphics = Graphics.FromImage(bBayes))
{
AStar astar = new AStar(finalMap.GetLength(0), finalMap.GetLength(1));
astar.Build(finalMap, new DPoint(destination.X, destination.Y), new DPoint((picBoxRovio.Location.X / 10) + (picBoxRovio.Width / 10 / 2), picBoxRovio.Location.Y / 10));
aStarPath = astar.path;
for (int i = 0; i < maxX; i++)
{
for (int j = 0; j < maxY; j++)
{
graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(preyProbability[i, j] * 255), System.Drawing.Color.DarkRed)), new DRectangle(i * 10, j * 10, 10, 10));
graphics.FillRectangle(new SolidBrush(DColor.FromArgb((int)(obstacleProbability[i, j] * 255), System.Drawing.Color.DarkBlue)), new DRectangle(i * 10, j * 10, 10, 10));
if (astar.inPath[i, j])
graphics.FillRectangle(new SolidBrush(DColor.Red), new DRectangle(i * 10, j * 10, 10, 10));
}
}
}
picBoxBayes.Image = bBayes;
// Check which cells are within the viewing cone.
if (viewConePoints != null)
{
for (int i = 0; i < maxX; i++)
{
for (int j = 0; j < maxY; j++)
{
DPoint a = new DPoint(i * 10 + 1, j * 10 + 1); // Top left
DPoint b = new DPoint((i + 1) * 10 - 1, j * 10 + 1); // Top right
DPoint c = new DPoint(i * 10 + 1, (j + 1) * 10 - 1); // Bottom left
DPoint d = new DPoint((i + 1) * 10 - 1, (j + 1) * 10 - 1); // Bottom right
if (!(PointInPolygon(a, viewConePoints) || PointInPolygon(b, viewConePoints)
|| PointInPolygon(c, viewConePoints) || PointInPolygon(d, viewConePoints)))
{
isCellVisible[i, j] = false;
}
else
{
preySensor[i, j] = false;
obstacleSensor[i, j] = false;
isCellVisible[i, j] = true;
}
}
}
}
if (robot.GetType() == typeof(Rovio.PredatorMap))
{
if (robot.IsPreySeen())
{
FindRelativeLocation(picBoxPrey, robot.preyRectangle, robot.GetPreyDistance(), 1, 1);
try
{
preySensor[(int)((picBoxPrey.Location.X / 10) + 1.5), (int)((picBoxPrey.Location.Y / 10) + 1.5)] = true;
} catch { }
}
else
picBoxPrey.Hide();
if ((robot as Rovio.BaseArena).IsObstacleSeen())
{
// Find obstacle position relative to the Rovio's position.
FindRelativeLocation(picBoxObstacle, robot.obstacleRectangle, robot.GetObstacleDistance(), 40, 3);
try
{
int p = (int)((picBoxObstacle.Location.X / 10) + 0.5);
int q = (int)((picBoxObstacle.Location.Y / 10) + 0.5);
// Populate 3x3 area with the obstacle.
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
obstacleSensor[(int)((picBoxObstacle.Location.X / 10) + i), (int)((picBoxObstacle.Location.Y / 10) + j)] = true;
}
catch { }
}
else
picBoxObstacle.Hide();
}
// Rotate the Rovio icon to the angle that the robot physically faces.
System.Drawing.Drawing2D.Matrix matrixRovio = new System.Drawing.Drawing2D.Matrix();
matrixRovio.RotateAt((float)robot.cumulativeAngle, new System.Drawing.Point(picBoxRovio.Location.X + (picBoxRovio.Size.Width / 2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height / 2)));
matrixRovio.Translate(0f, -0f);
DPoint[] rovioMovementPoints = {new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2), picBoxRovio.Location.Y + (picBoxRovio.Size.Height/2)),
new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) - 69, picBoxRovio.Location.Y-150),
new DPoint(picBoxRovio.Location.X+(picBoxRovio.Size.Width/2) + 69, picBoxRovio.Location.Y-150)};
matrixRovio.TransformPoints(rovioMovementPoints);
//.........这里部分代码省略.........
示例13: SetNewRovioPosition
/// <summary>
/// Set the Rovio's position using linear interpolation.
/// </summary>
private void SetNewRovioPosition()
{
Vector2 oldP = new Vector2(picBoxRovio.Location.X, picBoxRovio.Location.Y);
Vector2 newP = new Vector2(0, -1);
// Find the angle of the Rovio on the perimeter of the arena.
newP = Vector2.Transform(-Vector2.UnitY, Matrix.CreateRotationZ(MathHelper.ToRadians((float)robot.cumulativeAngle)));
newP /= MathHelper.Max(Math.Abs(newP.X), Math.Abs(newP.Y));
newP += Vector2.One;
newP *= new Vector2(260, 300) * 0.5f;
// Translate into the arena from the perimeter.
using (matrix = new System.Drawing.Drawing2D.Matrix())
{
matrix.Translate((int)newP.X, (int)newP.Y);
matrix.RotateAt((float)robot.cumulativeAngle, new DPoint(0, 0));
matrix.Translate(0f, (float)(robot.GetWallDist() * 100));
DPoint[] newPos = { new DPoint(0, 0) };
matrix.TransformPoints(newPos);
if (newPos[0].X < -400 || newPos[0].X > 600)
newPos[0] = new DPoint(-100, -100);
// Compensate for the alcoves.
if (newPos[0].X < 30 && (newPos[0].Y < 100 || newPos[0].Y > 200))
newPos[0].X += 30;
else if (newP.X > 230 && (newPos[0].Y < 100 || newPos[0].Y > 200))
newPos[0].X -= 30;
newP = Vector2.Lerp(oldP, new Vector2(newPos[0].X, newPos[0].Y), 0.1f);
picBoxRovio.Location = new DPoint((int)newP.X, (int)newP.Y);
}
}
示例14: RotateImage
public static Image RotateImage(Image inputImg, double degreeAngle)
{
//Corners of the image
PointF[] rotationPoints = { new PointF(0, 0),
new PointF(inputImg.Width, 0),
new PointF(0, inputImg.Height),
new PointF(inputImg.Width, inputImg.Height)};
//Rotate the corners
PointMath.RotatePoints(rotationPoints, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f), degreeAngle);
//Get the new bounds given from the rotation of the corners
//(avoid clipping of the image)
Rectangle bounds = PointMath.GetBounds(rotationPoints);
//An empy bitmap to draw the rotated image
Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(rotatedBitmap))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
//Transformation matrix
System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f));
m.Translate(-bounds.Left, -bounds.Top, System.Drawing.Drawing2D.MatrixOrder.Append); //shift to compensate for the rotation
g.Transform = m;
g.DrawImage(inputImg, 0, 0);
}
return (Image)rotatedBitmap;
}
示例15: InitializeVRT
private static SharpMap.Map InitializeVRT(ref int index, float angle)
{
SharpMap.Map map = new SharpMap.Map();
int ind = index - 6;
if (ind >= Vrts.Length) ind = 0;
if (!System.IO.File.Exists(RelativePath + Vrts[ind]))
{
throw new System.Exception("Make sure the data is in the relative directory: " + RelativePath);
}
SharpMap.Layers.GdalRasterLayer layer = new SharpMap.Layers.GdalRasterLayer("VirtualRasterTable", RelativePath + Vrts[ind]);
var ext = System.IO.Path.GetExtension(layer.Filename);
map.Layers.Add(layer);
_gdalSampleDataset = string.Format("'{0}'", ext != null ? ext.ToUpper() : string.Empty);
map.ZoomToExtents();
System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
//index++;
return map;
}