public static IGeometry Rotate(IGeometry g, double multipleOfPi) { var centre = EnvelopeCentre(g); var trans = AffineTransformation.RotationInstance(multipleOfPi * Math.PI, centre.X, centre.Y); return(trans.Transform(g)); }
public static IGeometry Scale(IGeometry g, double scale) { var centre = EnvelopeCentre(g); var trans = AffineTransformation.ScaleInstance(scale, scale, centre.X, centre.Y); return(trans.Transform(g)); }
public static IGeometry TranslateCentreToOrigin(Geometry g) { var centre = EnvelopeCentre(g); var trans = AffineTransformation.TranslationInstance(-centre.X, -centre.Y); return(trans.Transform(g)); }
private void Transform(object sender, RoutedEventArgs e) { try { this.uxTextBoxLog.Clear(); AffineTransformation affineTransformation = new AffineTransformation(DefaultDatabase.GetInstance().Points); affineTransformation.Transform(); this.outputLog = LogHelper.CreateLog(affineTransformation); MessageBox.Show("Успешна трансформация на координати!", Properties.Resources.MessageBoxTitleInformation, MessageBoxButton.OK, MessageBoxImage.Information); if (this.displayLogCheckBox.IsChecked == true) { this.uxTextBoxLog.Text = this.outputLog; } this.uxButtonSaveFile.IsEnabled = true; } catch (Exception ex) { MessageBox.Show(ex.StackTrace, Properties.Resources.MessageBoxTitleError, MessageBoxButton.OK, MessageBoxImage.Error); } }
public static IGeometry TranslateToOrigin(IGeometry g) { var lowerLeft = EnvelopeLowerLeft(g); var trans = AffineTransformation.TranslationInstance(-lowerLeft.X, -lowerLeft.Y); return(trans.Transform(g)); }
protected void MoveObserverToTransformation(HomogeneousPoint3D point, IPolyhedron3D obj) { Matrix affineMatrix = AffineTransformation.MoveOriginTo(point); obj.Transform(affineMatrix); obj.TransformRotationCenter(affineMatrix); }
static void Run(double p0x, double p0y, double p1x, double p1y, double p2x, double p2y, double pp0x, double pp0y, double pp1x, double pp1y, double pp2x, double pp2y ) { Coordinate p0 = new Coordinate(p0x, p0y); Coordinate p1 = new Coordinate(p1x, p1y); Coordinate p2 = new Coordinate(p2x, p2y); Coordinate pp0 = new Coordinate(pp0x, pp0y); Coordinate pp1 = new Coordinate(pp1x, pp1y); Coordinate pp2 = new Coordinate(pp2x, pp2y); AffineTransformationBuilder atb = new AffineTransformationBuilder( p0, p1, p2, pp0, pp1, pp2); AffineTransformation trans = atb.GetTransformation(); Coordinate dest = new Coordinate(); AssertEqualPoint(pp0, trans.Transform(p0, dest)); AssertEqualPoint(pp1, trans.Transform(p1, dest)); AssertEqualPoint(pp2, trans.Transform(p2, dest)); }
public static IGeometry ReflectInY(IGeometry g) { var centre = EnvelopeCentre(g); var trans = AffineTransformation.ScaleInstance(-1, 1, centre.X, centre.Y); return(trans.Transform(g)); }
///<summary> /// Checks that a transformation produces the expected result ///</summary> /// <param name="x">the input pt x</param> /// <param name="y">the input pt y</param> /// <param name="trans">the transformation</param> /// <param name="xp">the expected output x</param> /// <param name="yp">the expected output y</param> static void CheckTransformation(double x, double y, AffineTransformation trans, double xp, double yp) { var p = new Coordinate(x, y); var p2 = new Coordinate(); trans.Transform(p, p2); Assert.AreEqual(xp, p2.X, .00005); Assert.AreEqual(yp, p2.Y, .00005); // if the transformation is invertible, test the inverse try { var invTrans = trans.GetInverse(); var pInv = new Coordinate(); invTrans.Transform(p2, pInv); Assert.AreEqual(x, pInv.X, .00005); Assert.AreEqual(y, pInv.Y, .00005); double det = trans.Determinant; double detInv = invTrans.Determinant; Assert.AreEqual(det, 1.0 / detInv, .00005); } catch (NoninvertibleTransformationException) { } }
private void AddAffectedAreaLayer(Map map, Polygon affectedArea) { var geoms = new List <IGeometry>() { affectedArea }; if (!map.MapTransform.IsIdentity) { // affectedArea is aligned with Graphics Canvas (not with north arrow) // The following steps are simply to show this geom in world units var centreX = affectedArea.EnvelopeInternal.Centre.X; var centreY = affectedArea.EnvelopeInternal.Centre.Y; // apply negative rotation about center of polygon var rad = NetTopologySuite.Utilities.Degrees.ToRadians(map.MapTransformRotation); var trans = new AffineTransformation(); trans.Compose(AffineTransformation.TranslationInstance(-centreX, -centreY)); trans.Compose(AffineTransformation.RotationInstance(-rad)); var rotated = trans.Transform(affectedArea.Copy()); // calculate enclosing envelope var minX = rotated.Coordinates.Min(c => c.X); var minY = rotated.Coordinates.Min(c => c.Y); var maxX = rotated.Coordinates.Max(c => c.X); var maxY = rotated.Coordinates.Max(c => c.Y); var coords = new Coordinate[] { new Coordinate(minX, maxY), new Coordinate(maxX, maxY), new Coordinate(maxX, minY), new Coordinate(minX, minY), new Coordinate(minX, maxY), }; // rotate enclosing envelope back to world units trans = new AffineTransformation(); trans.Compose(AffineTransformation.RotationInstance(rad)); trans.Compose(AffineTransformation.TranslationInstance(centreX, centreY)); // construct geom to show on screen var enclosing = trans.Transform(new Polygon(new LinearRing(coords))); geoms.Add(enclosing); } var gp = new GeometryProvider(geoms); var vLayer = new VectorLayer("Affected Area") { DataSource = gp, SRID = map.SRID }; vLayer.Style.Fill = null; vLayer.Style.EnableOutline = true; //vLayer.Enabled = false; map.Layers.Add(vLayer); }
public void TestRotate1() { AffineTransformation t = AffineTransformation.RotationInstance(Math.PI / 2); CheckTransformation(10, 0, t, 0, 10); CheckTransformation(0, 10, t, -10, 0); CheckTransformation(-10, -10, t, 10, -10); }
public void TestRotate2() { var t = AffineTransformation.RotationInstance(1, 0); CheckTransformation(10, 0, t, 0, 10); CheckTransformation(0, 10, t, -10, 0); CheckTransformation(-10, -10, t, 10, -10); }
public void TestTranslate1() { var t = AffineTransformation.TranslationInstance(2, 3); CheckTransformation(1, 0, t, 3, 3); CheckTransformation(0, 0, t, 2, 3); CheckTransformation(-10, -5, t, -8, -2); }
public void TestTranslateRotate1() { var t = AffineTransformation.TranslationInstance(3, 3) .Rotate(Math.PI / 2); CheckTransformation(10, 0, t, -3, 13); CheckTransformation(-10, -10, t, 7, -7); }
public void TestReflectXyxy1() { var t = AffineTransformation.ReflectionInstance(0, 5, 5, 0); CheckTransformation(5, 0, t, 5, 0); CheckTransformation(0, 0, t, 5, 5); CheckTransformation(-10, -10, t, 15, 15); }
public void TestScale1() { var t = AffineTransformation.ScaleInstance(2, 3); CheckTransformation(10, 0, t, 20, 0); CheckTransformation(0, 10, t, 0, 30); CheckTransformation(-10, -10, t, -20, -30); }
private void CreatePdfOverviewMap(PdfContentByte content, Configuration.PrintTemplateContentRow row) { AppState appState = new AppState(); appState.Application = _appState.Application; Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application); appState.MapTab = application.OverviewMapID; appState.Extent = application.GetFullExtentEnvelope(); int pixelWidth = Convert.ToInt32(row.Width * PixelsPerInch); int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch); MapMaker mapMaker = new MapMaker(appState, pixelWidth, pixelHeight, 2); MapImageData mapImageData = mapMaker.GetImage(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(new MemoryStream(mapImageData.Image)); Transformation trans = new AffineTransformation(pixelWidth * 2, pixelHeight * 2, appState.Extent); MapGraphics mapGraphics = MapGraphics.FromImage(bitmap, trans); double minSize = (trans.Transform(new Coordinate(1, 0)).X - trans.Transform(new Coordinate(0, 0)).X) * 12; Envelope extent = new Envelope(new Coordinate(_appState.Extent.MinX, _appState.Extent.MinY), new Coordinate(_appState.Extent.MaxX, _appState.Extent.MaxY)); if (extent.Width < minSize) { extent = new Envelope(new Coordinate(extent.Centre.X - minSize * 0.5, extent.MinY), new Coordinate(extent.Centre.X + minSize * 0.5, extent.MaxY)); } if (extent.Height < minSize) { extent = new Envelope(new Coordinate(extent.MinX, extent.Centre.Y - minSize * 0.5), new Coordinate(extent.MaxX, extent.Centre.Y + minSize * 0.5)); } System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(64, System.Drawing.Color.Red)); System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 4); mapGraphics.FillEnvelope(brush, extent); mapGraphics.DrawEnvelope(pen, extent); MemoryStream stream = new MemoryStream(); bitmap.Save(stream, mapImageData.Type == CommonImageType.Png ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg); byte[] mapImage = stream.ToArray(); float originX = Convert.ToSingle(row.OriginX) * PointsPerInch; float originY = Convert.ToSingle(row.OriginY) * PointsPerInch; float width = Convert.ToSingle(row.Width) * PointsPerInch; float height = Convert.ToSingle(row.Height) * PointsPerInch; iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage); image.SetAbsolutePosition(originX, originY); image.ScaleAbsolute(width, height); content.AddImage(image); CreatePdfBox(content, row, false); }
public void TestReflectXy1() { AffineTransformation t = AffineTransformation.ReflectionInstance(1, 1); CheckTransformation(10, 0, t, 0, 10); CheckTransformation(0, 10, t, 10, 0); CheckTransformation(-10, -10, t, -10, -10); CheckTransformation(-3, -4, t, -4, -3); }
public void TestRotateAroundPoint2() { var t = AffineTransformation.RotationInstance(1, 0, 1, 1); CheckTransformation(1, 1, t, 1, 1); CheckTransformation(10, 0, t, 2, 10); CheckTransformation(0, 10, t, -8, 0); CheckTransformation(-10, -10, t, 12, -10); }
public void TestReflectXy2() { var t = AffineTransformation.ReflectionInstance(1, -1); CheckTransformation(10, 0, t, 0, -10); CheckTransformation(0, 10, t, -10, 0); CheckTransformation(-10, -10, t, 10, 10); CheckTransformation(-3, -4, t, 4, 3); }
public AffineTransform(AffineTransformation affineTransformation) { _affineTransformation = affineTransformation; _inverseAffineTransformation = affineTransformation.GetInverse(); _transformation = affineTransformation; DimSource = DimTarget = 2; //WKT = "NTS AffineTransformation"; }
static void CheckTransformation(AffineTransformation trans0, AffineTransformation trans1) { double[] m0 = trans0.MatrixEntries; double[] m1 = trans1.MatrixEntries; for (int i = 0; i < m0.Length; i++) { Assert.AreEqual(m0[i], m1[i], 0.000005); } }
public void TestTransform1() { var trans = new AffineTransformation(); trans.Rotate(1); trans.Translate(10, 10); trans.Scale(2, 2); RunTransform(trans, ctl0, ctl1, ctl2); }
public void TestCompose3() { var t0 = AffineTransformation.ReflectionInstance(0, 10, 10, 0); t0.Translate(-10, -10); var t1 = AffineTransformation.ReflectionInstance(0, 0, -1, 1); CheckTransformation(t0, t1); }
public void TestCompose2() { var t0 = AffineTransformation.ReflectionInstance(0, 0, 1, 0); t0.Reflect(0, 0, 0, -1); var t1 = AffineTransformation.RotationInstance(Math.PI); CheckTransformation(t0, t1); }
/// <summary> /// Applies the rotation transformation to the dataset images. /// </summary> /// <param name="dataset">The dataset.</param> /// <returns>The rotated images.</returns> private List <MnistImage> ApplyRotationTransformation(List <MnistImage> dataset) { var result = new List <MnistImage>(); var random = new Random(); result.AddRange(dataset.Select(x => new MnistImage(x.Label, AffineTransformation.Rotate(x.Pixels, random.NextDouble() > 0.5 ? 0.5 : -0.5)))); return(result); }
public static MultiPolygon CrossedComb(Envelope env, int size, GeometryFactory geomFact) { var comb1 = CreateComb(env, size, geomFact); var centre = env.Centre; var trans = AffineTransformation.RotationInstance(0.5 * System.Math.PI, centre.X, centre.Y); var comb2 = (Polygon)trans.Transform(comb1); var mp = geomFact.CreateMultiPolygon(new [] { comb1, comb2 }); return(mp); }
public void SetUp() { var a = new AffineTransformation(); a.SetToTranslation(10, 10); _mathTransform = new AffineTransform(a); _factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(new PrecisionModel(1000d)); _reader = new WKTReader(_factory); }
protected IGeometry Rotate(IGeometry geom) { if (_rotationAngle != 0.0) { var centre = _dim.Centre; var trans = AffineTransformation.RotationInstance(_rotationAngle, centre.X, centre.Y); geom.Apply(trans); } return(geom); }
public void TestTransform2() { var trans = new AffineTransformation(); trans.Rotate(3); trans.Translate(10, 10); trans.Scale(2, 10); trans.Shear(5, 2); trans.Reflect(5, 8, 10, 2); RunTransform(trans, ctl0, ctl1, ctl2); }
private void Initialize(AppState appState, int width, int height, double resolution) { _appState = appState; _width = width; _height = height; _resolution = resolution; if (_width * _resolution > 2048) { _resolution *= 2048 / (_resolution * _width); } if (_height * _resolution > 2048) { _resolution *= 2048 / (_resolution * _height); } _extent = _appState.Extent; _extent.Reaspect(_width, _height); _transform = new AffineTransformation(_width, _height, _extent); }
/// <summary> /// Reverses the transformation /// </summary> public void Invert() { if (_transformation == _affineTransformation) { if (_inverseAffineTransformation == null) throw new NotSupportedException(); _transformation = _inverseAffineTransformation; } else { _transformation = _affineTransformation; } }
public void TestTransform1() { AffineTransformation trans = new AffineTransformation(); trans.Rotate(1); trans.Translate(10, 10); trans.Scale(2, 2); RunTransform(trans, ctl0, ctl1, ctl2); }
private static void ApplyTransform(string file, AffineTransformation at, string suffix = null) { if (string.IsNullOrEmpty(suffix)) suffix = "_neu"; string outFile = Path.GetFileName(file) + suffix + Path.GetExtension(file); if (File.Exists(outFile)) File.Delete(outFile); Console.WriteLine("Performing transformation using \n{0}", at); using (StreamWriter sw = new StreamWriter(File.OpenWrite(outFile))) { using (StreamReader sr = new StreamReader(File.OpenRead(file))) { while (!sr.EndOfStream) { string line = sr.ReadLine(); if (!string.IsNullOrEmpty(line)) { if (!line.StartsWith("#")) { string[] parts = line.Split(','); Coordinate src = new Coordinate(double.Parse(parts[2], NumberFormatInfo.InvariantInfo), double.Parse(parts[3], NumberFormatInfo.InvariantInfo)); Coordinate dst = new Coordinate(); dst = at.Transform(src, dst); parts[2] = dst.X.ToString(NumberFormatInfo.InvariantInfo); parts[3] = dst.Y.ToString(NumberFormatInfo.InvariantInfo); line = string.Join(",", parts); } } sw.WriteLine(line); } } } }
private void PrepareAffineTransformations() { _affine = new AffineTransformation(Convert.ToInt32(textBox1.Text), _random); }
public void TestTransform2() { AffineTransformation trans = new AffineTransformation(); trans.Rotate(3); trans.Translate(10, 10); trans.Scale(2, 10); trans.Shear(5, 2); trans.Reflect(5, 8, 10, 2); RunTransform(trans, ctl0, ctl1, ctl2); }
private static void RunTransform(AffineTransformation trans, Coordinate p0, Coordinate p1, Coordinate p2) { Coordinate pp0 = trans.Transform(p0, new Coordinate()); Coordinate pp1 = trans.Transform(p1, new Coordinate()); Coordinate pp2 = trans.Transform(p2, new Coordinate()); AffineTransformationBuilder atb = new AffineTransformationBuilder( p0, p1, p2, pp0, pp1, pp2); AffineTransformation atbTrans = atb.GetTransformation(); Coordinate dest = new Coordinate(); AssertEqualPoint(pp0, atbTrans.Transform(p0, dest)); AssertEqualPoint(pp1, atbTrans.Transform(p1, dest)); AssertEqualPoint(pp2, atbTrans.Transform(p2, dest)); }
///<summary> /// Checks that a transformation produces the expected result ///</summary> /// <param name="x">the input pt x</param> /// <param name="y">the input pt y</param> /// <param name="trans">the transformation</param> /// <param name="xp">the expected output x</param> /// <param name="yp">the expected output y</param> static void CheckTransformation(double x, double y, AffineTransformation trans, double xp, double yp) { Coordinate p = new Coordinate(x, y); Coordinate p2 = new Coordinate(); trans.Transform(p, p2); Assert.AreEqual(xp, p2.X, .00005); Assert.AreEqual(yp, p2.Y, .00005); // if the transformation is invertible, test the inverse try { AffineTransformation invTrans = trans.GetInverse(); Coordinate pInv = new Coordinate(); invTrans.Transform(p2, pInv); Assert.AreEqual(x, pInv.X, .00005); Assert.AreEqual(y, pInv.Y, .00005); double det = trans.Determinant; double detInv = invTrans.Determinant; Assert.AreEqual(det, 1.0 / detInv, .00005); } catch (NoninvertibleTransformationException) { } }