internal static bool TransformationEqual(LinearTransformation x, LinearTransformation y) { return(x.RotateX.Equals(y.RotateX) && x.RotateY.Equals(y.RotateY) && x.RotateZ.Equals(y.RotateZ) && x.ScaleX.Equals(y.ScaleX) && x.ScaleY.Equals(y.ScaleY) && x.ScaleZ.Equals(y.ScaleZ) && x.TranslateX.Equals(y.TranslateX) && x.TranslateY.Equals(y.TranslateY) && x.TranslateZ.Equals(y.TranslateZ) && x.TransformationOrder.Equals(y.TransformationOrder)); }
internal static bool TransformationEqual(LinearTransformation x, LinearTransformation y) { return x.RotateX.Equals(y.RotateX) && x.RotateY.Equals(y.RotateY) && x.RotateZ.Equals(y.RotateZ) && x.ScaleX.Equals(y.ScaleX) && x.ScaleY.Equals(y.ScaleY) && x.ScaleZ.Equals(y.ScaleZ) && x.TranslateX.Equals(y.TranslateX) && x.TranslateY.Equals(y.TranslateY) && x.TranslateZ.Equals(y.TranslateZ) && x.TransformationOrder.Equals(y.TransformationOrder); }
/// <summary> /// 获取转换后的点 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="param4"></param> /// <returns></returns> private HorizontalCoordinate GetTransformedPoint(double x, double y, Matrix param4) { var offset = ((int)x / 1000000) * 1000000; // 坐标转换 x = x - offset; var sourceCoordinate = new HorizontalCoordinate(x, y); var targetCoordinate = LinearTransformation.Transform(sourceCoordinate, param4); return(new HorizontalCoordinate(targetCoordinate.X + offset, targetCoordinate.Y)); }
public void Transform(LinearTransformation linearTransformation) { linearTransformation.TranslateX = TranslateX; linearTransformation.TranslateY = TranslateY; linearTransformation.TranslateZ = TranslateZ; linearTransformation.RotateX = RotateX; linearTransformation.RotateY = RotateY; linearTransformation.RotateZ = RotateZ; linearTransformation.ScaleX = ScaleX; linearTransformation.ScaleY = ScaleY; linearTransformation.ScaleZ = ScaleZ; linearTransformation.TransformationOrder = TransformationOrder; }
public void GetSketchPointInfo(int index, ref double[] adfX, ref double[] adfY, ref double[] adfZ, Matrix param4) { var marker = m_pointOverlay.Markers[index]; var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; projection.LongitudeOfOrigin = Math.Round(marker.Position.Lng / 3) * 3; projection.Forward(marker.Position.Lat, marker.Position.Lng, out adfX[0], out adfY[0]); var sourceCoordinate = new HorizontalCoordinate(adfX[0], adfY[0]); var targetCoordinate = LinearTransformation.Transform(sourceCoordinate, param4); adfX[0] = targetCoordinate.X + projection.LongitudeOfOrigin / 3 * 1000000; adfY[0] = targetCoordinate.Y; }
public static Transformation CreateForm(LinearTransformation linearTransformation) { return(new Transformation { TranslateX = linearTransformation.TranslateX, TranslateY = linearTransformation.TranslateY, TranslateZ = linearTransformation.TranslateZ, RotateX = linearTransformation.RotateX, RotateY = linearTransformation.RotateY, RotateZ = linearTransformation.RotateZ, ScaleX = linearTransformation.ScaleX, ScaleY = linearTransformation.ScaleY, ScaleZ = linearTransformation.ScaleZ, TransformationOrder = linearTransformation.TransformationOrder }); }
private static ITransformation <double>[] CreateScaling(IDataset dataset, int[] rows, IReadOnlyCollection <string> allowedInputVariables) { var trans = new ITransformation <double> [allowedInputVariables.Count]; int i = 0; foreach (var variable in allowedInputVariables) { var lin = new LinearTransformation(allowedInputVariables); var max = dataset.GetDoubleValues(variable, rows).Max(); var min = dataset.GetDoubleValues(variable, rows).Min(); lin.Multiplier = 1.0 / (max - min); lin.Addend = -min / (max - min); trans[i] = lin; i++; } return(trans); }
/// <summary> /// 取图形范围 /// </summary> /// <param name="adfMinBound"></param> /// <param name="adfMaxBound"></param> /// <param name="param4"></param> /// <returns></returns> private RectLatLng GetShapeRect(double[] adfMinBound, double[] adfMaxBound, Matrix param4) { double minX, minY, maxX, maxY; minX = adfMinBound[0]; minY = adfMinBound[1]; var minZone = (int)minX / 1000000; minX = minX - minZone * 1000000; maxX = adfMaxBound[0]; maxY = adfMaxBound[1]; var maxZone = (int)maxX / 1000000; maxX = maxX - maxZone * 1000000; // 坐标转换(不要加大数) var minXY = LinearTransformation.Transform(new HorizontalCoordinate(minX, minY), param4); var maxXY = LinearTransformation.Transform(new HorizontalCoordinate(maxX, maxY), param4); var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; // 再转成经纬度(加上大数,因为需要计算投影带号) double lat, lng; projection.LongitudeOfOrigin = minZone * 3; projection.Reverse(minXY.X, minXY.Y, out lat, out lng); var minLB = new GeocentricCoordinate(lat, lng); projection.LongitudeOfOrigin = maxZone * 3; projection.Reverse(maxXY.X, maxXY.Y, out lat, out lng); var maxLB = new GeocentricCoordinate(lat, lng); // 取得图形范围用于显示 var rect = new RectLatLng(maxLB.Latitude.Digital, minLB.Longitude.Digital, maxLB.Longitude.Digital - minLB.Longitude.Digital, maxLB.Latitude.Digital - minLB.Latitude.Digital); return(rect); }
public void GetSketchPolygonInfo(int index, ref double[] adfX, ref double[] adfY, ref double[] adfZ, Matrix param4) { var polygon = m_polygonOverlay.Polygons[index]; var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; for (int i = 0; i < polygon.Points.Count; i++) { projection.LongitudeOfOrigin = Math.Round(polygon.Points[i].Lng / 3) * 3; projection.Forward(polygon.Points[i].Lat, polygon.Points[i].Lng, out adfX[i], out adfY[i]); var sourceCoordinate = new HorizontalCoordinate(adfX[i], adfY[i]); var targetCoordinate = LinearTransformation.Transform(sourceCoordinate, param4); adfX[i] = targetCoordinate.X + projection.LongitudeOfOrigin / 3 * 1000000; adfY[i] = targetCoordinate.Y; } }
public void Transform(Matrix mat) { RotationalTransformation rot = new RotationalTransformation(); rot.Matrix = mat; rot.RotateDegreesAroundOrigin(mRotation); LinearTransformation lt = new LinearTransformation(); lt.Matrix = mat; if (mAspect < 0) { lt.StretchX = 1 + mAspect; lt.Transform(); } if (mAspect > 0) { lt.StretchY = 1 - +mAspect; lt.Transform(); } }
/// <summary> /// 获取转换后的点 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="param4"></param> /// <returns></returns> private PointLatLng GetTransformedPoint(double x, double y, Matrix param4) { var projection = new GaussKrugerProjection(); projection.Ellipsoid = ReferenceEllipsoid.International1975; var zone = (int)x / 1000000; x = x - zone * 1000000; // 坐标转换(不要加大数) var sourceCoordinate = new HorizontalCoordinate(x, y); var targetCoordinate = LinearTransformation.Transform(sourceCoordinate, param4); // 再转成经纬度(加上大数,因为需要计算投影带号) double lat, lng; projection.LongitudeOfOrigin = zone * 3; projection.Reverse(targetCoordinate.X, targetCoordinate.Y, out lat, out lng); return(new PointLatLng(lat, lng)); }
private void drawSingleVector(float t) { Vector3 center = transform.position; float theta = Mathf.Deg2Rad * t * travelSpeed; float dx = -1 * Mathf.Cos(theta) * lineSize * radius; float dy = -1 * Mathf.Sin(theta) * lineSize * radius; float dz = (transform.position.z - gameObject.transform.position.z) * lineSize; Vector3 pos = new Vector3(center.x + dx, center.y + dy, center.z + dz); float arrowHeadRotationInitial = Mathf.Atan((transform.position.z - gameObject.transform.position.z) / radius) - Mathf.PI / 4; Vector3 arrowHeadLeftInitial = LinearTransformation.xzRotation(new Vector3(arrowSize, 0, 0), arrowHeadRotationInitial, LinearTransformation.CLOCKWISE); Vector3 arrowHeadRightInitial = LinearTransformation.xzRotation(new Vector3(0, 0, -arrowSize), arrowHeadRotationInitial, LinearTransformation.CLOCKWISE); Vector3 arrowHeadLeft = LinearTransformation.xyRotation(arrowHeadLeftInitial, theta, LinearTransformation.COUNTERCLOCKWISE); Vector3 arrowHeadRight = LinearTransformation.xyRotation(arrowHeadRightInitial, theta, LinearTransformation.COUNTERCLOCKWISE); line.SetPosition(0, center); line.SetPosition(1, pos); line.SetPosition(2, pos + arrowHeadLeft); line.SetPosition(3, pos); line.SetPosition(4, pos + arrowHeadRight); }
public void TestMethod1() { Transformation tr; tr = new LeftRotateTransformation(3); Assert.AreEqual((ulong)4567890123, tr.transform(1234567890)); tr = new LinearTransformation(11, 3); Assert.AreEqual(3580246793, tr.transform(1234567890)); Assert.IsTrue(ModularExponentiateTransformation.primeFactors(60).SequenceEqual(new List <ulong> { 2, 2, 3, 5 })); Assert.IsTrue(ModularExponentiateTransformation.primeFactors(1).SequenceEqual(new List <ulong> ())); Assert.IsTrue(ModularExponentiateTransformation.primeFactors(15966421).SequenceEqual(new List <ulong> { 15966421 })); Assert.IsNotNull(new ModularExponentiateTransformation(2, 2147483543, 269, 15966421, 5, 282013133, 17, 17, 17)); Assert.IsNotNull(new LinearTransformation()); Assert.IsNotNull(new LeftRotateTransformation()); tr = Transformation.StringConstrucor("{lr:3}"); Assert.AreEqual((ulong)4567890123, tr.transform(1234567890)); tr = Transformation.StringConstrucor("{ln:b,3}"); Assert.AreEqual(3580246793, tr.transform(1234567890)); tr = Transformation.StringConstrucor("{me:2,1___-n,4d,YW3l,5,gPOTd,h,h,h}"); Assert.IsNotNull(tr); Console.WriteLine("2147483543.To64 => " + Transformation.To64(2147483543)); Console.WriteLine("269.To64 => " + Transformation.To64(269)); Console.WriteLine("15966421.To64 => " + Transformation.To64(15966421)); Console.WriteLine("282013133.To64 => " + Transformation.To64(282013133)); Console.WriteLine("17.To64 => " + Transformation.To64(17)); tr = new ModularExponentiateTransformation(); Console.WriteLine(tr.ToString()); Console.WriteLine("me(1234567890) => " + tr.transform(1234567890).ToString()); Assert.IsNotNull(tr); IdEncryption enc = IdEncryption.StringConstructor("{ln:b,3}{lr:3}"); Assert.AreEqual((ulong)246793358, enc.encrypt(1234567890)); Assert.AreEqual("op", Transformation.To64(24 * 64 + 25)); Assert.AreEqual((ulong)24 * 64 + 26, Transformation.From64("oq")); bool thrown = false; try { Transformation.From64("あああ"); } catch (ArgumentException) { thrown = true; } Assert.AreEqual(true, thrown); enc = new IdEncryption(new List <Transformation>() { new LinearTransformation(79565413, 1974568793), new LeftRotateTransformation(5) }); Console.WriteLine("enc2: " + enc.ToString()); Assert.IsNotNull(enc); BirthDateModifier bdmod = new BirthDateTo0101(); Assert.AreEqual("20150101", bdmod.modify("20151201", null)); Assert.AreEqual("20160101", bdmod.modify("20167890", null)); bdmod = BirthDateModifier.TypedConstructor(0); //AdmDate Assert.AreEqual("19801201", bdmod.modify("19800503", "20151201")); Assert.AreEqual("19820503", bdmod.modify("19811201", "20150503")); Assert.AreEqual(getAge(19800503, 20151201), getAge(19801201, 20151201)); Assert.AreEqual(getAge(19811201, 20150503), getAge(19820503, 20150503)); Assert.AreEqual("19811201", bdmod.modify("19811201", "20151201")); PostalCodeModifier pcmod = new PostalCodeTo0000000(); Assert.AreEqual("0000000", pcmod.modify("1234567")); Assert.AreEqual("0000000", pcmod.modify("9999999")); }
private void menuItemExportTransformedSketch_Click(object sender, EventArgs e) { var dialog = new SaveFileDialog(); dialog.Filter = "Shp文件(*.shp)|*.shp"; dialog.AddExtension = true; if (dialog.ShowDialog() == DialogResult.OK) { var xmlDialog = new OpenFileDialog(); xmlDialog.Filter = "控制点坐标(*.xml)|*.xml"; if (xmlDialog.ShowDialog() == DialogResult.OK) { List <HorizontalCoordinate> sourceCoordinates, targetCoordinates; KVS.Open(dialog.FileName, out targetCoordinates, out sourceCoordinates); var param4 = LinearTransformation.GetTransformationParameter(sourceCoordinates, targetCoordinates); var pathName = Path.GetDirectoryName(dialog.FileName); var fileName = Path.GetFileNameWithoutExtension(dialog.FileName); var nVertices = m_mapDocument.GetSketchPointCount(); double[] adfX = new double[1]; double[] adfY = new double[1]; double[] adfZ = new double[1]; var shpFileName = string.Format(@"{0}\{1}_point.shp", pathName, fileName); var hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.Point); for (int i = 0; i < nVertices; i++) { m_mapDocument.GetSketchPointInfo(i, ref adfX, ref adfY, ref adfZ, param4); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.Point, nVertices, adfX, adfY, adfZ); Shapelib.SHPWriteObject(hSHP, -1, psObject); } Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("点文件已存为:" + shpFileName); nVertices = m_mapDocument.GetSketchPolylineCount(); shpFileName = string.Format(@"{0}\{1}_polyline.shp", pathName, fileName); hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.PolyLine); for (int i = 0; i < nVertices; i++) { var count = m_mapDocument.GetSketchPolylinePointCount(i); adfX = new double[count]; adfY = new double[count]; adfZ = new double[count]; m_mapDocument.GetSketchPolylineInfo(i, ref adfX, ref adfY, ref adfZ, param4); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.PolyLine, count, adfX, adfY, adfZ); var iLine = Shapelib.SHPWriteObject(hSHP, -1, psObject); } Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("线文件已存为:" + shpFileName); nVertices = m_mapDocument.GetSketchPolygonCount(); shpFileName = string.Format(@"{0}\{1}_polygon.shp", pathName, fileName); hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.Polygon); for (int i = 0; i < nVertices; i++) { var count = m_mapDocument.GetSketchPolygonPointCount(i); adfX = new double[count]; adfY = new double[count]; adfZ = new double[count]; m_mapDocument.GetSketchPolygonInfo(i, ref adfX, ref adfY, ref adfZ, param4); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.Polygon, count, adfX, adfY, adfZ); var iPolygon = Shapelib.SHPWriteObject(hSHP, -1, psObject); } Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("面文件已存为:" + shpFileName); } } }
private void OpenLayer(string shpFileName, string xmlFileName = "") { var pathName = Path.GetDirectoryName(shpFileName); var fileName = Path.GetFileNameWithoutExtension(shpFileName); var shp = string.Format(@"{0}\{1}.shp", pathName, fileName); var hSHP = Shapelib.SHPOpen(shp, "rb"); var dbf = string.Format(@"{0}\{1}.dbf", pathName, fileName); var hDBF = Shapelib.DBFOpen(dbf, "rb"); // 实体数 int pnEntities = 0; // 形状类型 Shapelib.ShapeType pshpType = Shapelib.ShapeType.NullShape; // 界限坐标数组 double[] adfMinBound = new double[4], adfMaxBound = new double[4]; // 获取实体数、形状类型、界限坐标等信息 Shapelib.SHPGetInfo(hSHP, ref pnEntities, ref pshpType, adfMinBound, adfMaxBound); var sourceCoordinates = new List <HorizontalCoordinate>(); var targetCoordinates = new List <HorizontalCoordinate>(); if (!string.IsNullOrEmpty(xmlFileName)) { KVS.Open(xmlFileName, out sourceCoordinates, out targetCoordinates); } var param4 = string.IsNullOrEmpty(xmlFileName) ? null : LinearTransformation.GetTransformationParameter(sourceCoordinates, targetCoordinates); var rect = string.IsNullOrEmpty(xmlFileName) ? GetShapeRect(adfMinBound, adfMaxBound) : GetShapeRect(adfMinBound, adfMaxBound, param4); var node = new TreeNode(shp); node.Tag = rect; node.Checked = true; node.ExpandAll(); GMapOverlay overlay = new GMapOverlay(shp); for (int iShape = 0; iShape < pnEntities; iShape++) { // SHPObject对象 Shapelib.SHPObject shpObject = new Shapelib.SHPObject(); // 读取SHPObject对象指针 var shpObjectPtr = Shapelib.SHPReadObject(hSHP, iShape); // 忽略可能存在问题的实体 if (shpObjectPtr == IntPtr.Zero) { continue; } // 指针转换为SHPObject对象 Marshal.PtrToStructure(shpObjectPtr, shpObject); // 顶点数 int nVertices = shpObject.nVertices; // 顶点的X坐标数组 var padfX = new double[nVertices]; // 将顶点的X坐标数组指针转换为数组 Marshal.Copy(shpObject.padfX, padfX, 0, nVertices); // 顶点的Y坐标数组 var padfY = new double[nVertices]; // 将顶点的Y坐标数组指针转换为数组 Marshal.Copy(shpObject.padfY, padfY, 0, nVertices); int iField = Shapelib.DBFGetFieldIndex(hDBF, "名称"); string entityName = Shapelib.DBFReadStringAttribute(hDBF, iShape, iField); // var entityName = Enum.GetName(pshpType.GetType(), pshpType) + iShape; var points = new List <PointLatLng>(); var entityNode = new TreeNode(); entityNode.Text = entityName; switch (pshpType) { case Shapelib.ShapeType.Point: var pointMarker = string.IsNullOrEmpty(xmlFileName) ? GetPoint(padfX[0], padfY[0]) : GetTransformedPoint(padfX[0], padfY[0], param4); points.Add(pointMarker); UpdateOverlay(ref overlay, pshpType, points, entityName); entityNode.Tag = overlay.Id; break; default: var minPoint = new PointLatLng(); var maxPoint = new PointLatLng(); for (int i = 0; i < nVertices; i++) { var point = string.IsNullOrEmpty(xmlFileName) ? GetPoint(padfX[i], padfY[i]) : GetTransformedPoint(padfX[i], padfY[i], param4); points.Add(point); if (i == 0) { minPoint.Lat = maxPoint.Lat = point.Lat; minPoint.Lng = maxPoint.Lng = point.Lng; } else { if (point.Lng > maxPoint.Lng) { maxPoint.Lng = point.Lng; } if (point.Lat > maxPoint.Lat) { maxPoint.Lat = point.Lat; } if (point.Lng < minPoint.Lng) { minPoint.Lng = point.Lng; } if (point.Lat < minPoint.Lat) { minPoint.Lat = point.Lat; } } } UpdateOverlay(ref overlay, pshpType, points, entityName); var entityRect = new RectLatLng(maxPoint.Lat, minPoint.Lng, maxPoint.Lng - minPoint.Lng, maxPoint.Lat - minPoint.Lat); entityNode.Tag = entityRect; break; } node.Nodes.Add(entityNode); } Shapelib.DBFClose(hDBF); Shapelib.SHPClose(hSHP); m_layerWindow.AddNode(node); m_mapDocument.AddOverlayer(overlay); if (pshpType == Shapelib.ShapeType.Point) { m_mapDocument.Zoom(overlay.Id); } else { m_mapDocument.Zoom(rect); } }
public static Transformation CreateForm(LinearTransformation linearTransformation) { return new Transformation { TranslateX = linearTransformation.TranslateX, TranslateY = linearTransformation.TranslateY, TranslateZ = linearTransformation.TranslateZ, RotateX = linearTransformation.RotateX, RotateY = linearTransformation.RotateY, RotateZ = linearTransformation.RotateZ, ScaleX = linearTransformation.ScaleX, ScaleY = linearTransformation.ScaleY, ScaleZ = linearTransformation.ScaleZ, TransformationOrder = linearTransformation.TransformationOrder }; }
/// <summary> /// Push a new object space onto the stack and then apply a <see cref="SharpGL.SceneGraph.Transformations.LinearTransformation"/>. /// </summary> /// <param name="gl">The OpenGL render context.</param> /// <param name="tranformation">The <see cref="SharpGL.SceneGraph.Transformations.LinearTransformation"/> to apply</param> public void PushObjectSpace(OpenGL gl, LinearTransformation tranformation) { gl.PushMatrix(); tranformation.Transform(gl); Rotate(gl); }