Thomas
March 19, 2010, 10:58am
1
Hello,
I have to create shapes (Point, Lines, Rectangle) and position them beside a line (baseline).
As parameter I have the position (distance) on the base line where the elements are in right angle to. Also I know the offset and if the shape has to be positioned left or right side to the base line.
If I use getPointOnALine() I can get the points the shapes would have if they were located on the line. But how can I move those point in a right angle and given distance?
Thanks Thomas
Val
March 19, 2010, 5:20pm
2
Please, look at the code I am using below. Basically, I think that with the function GetAngleFromTwoVertices you have what you need.
winformsMap1.MapUnit = GeographyUnit.Meter; winformsMap1.CurrentExtent = new RectangleShape(0, 90, 180, 0); LineShape lineShape = new LineShape(); lineShape.Vertices.Add(new Vertex(10, 60)); lineShape.Vertices.Add(new Vertex(130, 20)); PointShape pointShape1 = lineShape.GetPointOnALine(StartingPoint.FirstPoint, 30); double Angle = GetAngleFromTwoVertices(lineShape.Vertices[0], lineShape.Vertices[1]); double offsetAngle1 = Angle; double offsetAngle2 = Angle + 180; PointShape offsetPointShape1 = (PointShape)pointShape1.CloneDeep(); PointShape offsetPointShape2 = (PointShape)pointShape1.CloneDeep(); offsetPointShape1.TranslateByDegree(20, offsetAngle1); offsetPointShape2.TranslateByDegree(20, offsetAngle2); InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 3, true); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Green, 10); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; inMemoryFeatureLayer.Open(); inMemoryFeatureLayer.EditTools.BeginTransaction(); inMemoryFeatureLayer.EditTools.Add(new Feature(lineShape)); inMemoryFeatureLayer.EditTools.Add(new Feature(pointShape1)); inMemoryFeatureLayer.EditTools.Add(new Feature(offsetPointShape1)); inMemoryFeatureLayer.EditTools.Add(new Feature(offsetPointShape2)); inMemoryFeatureLayer.EditTools.CommitTransaction(); inMemoryFeatureLayer.Close(); LayerOverlay layerOverlay = new LayerOverlay(); layerOverlay.Layers.Add(inMemoryFeatureLayer); winformsMap1.Overlays.Add(layerOverlay); winformsMap1.Refresh();
Val
March 19, 2010, 5:22pm
3
private static double GetAngleFromTwoVertices(Vertex fromVertex, Vertex toVertex) { double alpha = 0; if (fromVertex.X != toVertex.X) { double tangentAlpha = (fromVertex.Y - toVertex.Y) / (toVertex.X - fromVertex.X); alpha = Math.Atan(tangentAlpha) * 180 / Math.PI; if (alpha < 0) { alpha += 360; } } else { alpha = (fromVertex.Y > toVertex.Y) ? 90 : 270; } return alpha; }
Val
March 23, 2010, 11:09am
4
I let you know that we made a project in the Code Community from your idea of offsetting points at a right angle. You can check it out:
code.thinkgeo.com/projects/show/offsetrightangle