private void chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            if(sender is ChartArea)
            {
                ChartArea area = (ChartArea)sender;
                if(area.Name == "Default")
                {
                    Point3D [] pt3d = new Point3D[4];
                    pt3d[0] = new Point3D();
                    pt3d[1] = new Point3D();
                    pt3d[2] = new Point3D();
                    pt3d[3] = new Point3D();

                    float depth = (float)area.GetSeriesDepth(chart1.Series[0]);
                    float zpos = (float)area.GetSeriesZPosition(chart1.Series[0]);

                    pt3d[0].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[7].XValue);
                    pt3d[0].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[7].YValues[1]);
                    pt3d[0].Z = depth;

                    pt3d[1].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[6].XValue);
                    pt3d[1].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[6].YValues[0]);
                    pt3d[1].Z = depth;

                    pt3d[2].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[3].XValue);
                    pt3d[2].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[3].YValues[1]);
                    pt3d[2].Z = depth;

                    pt3d[3].Y = (float)area.AxisX.ValueToPosition(chart1.Series["Estimated"].Points[2].XValue);
                    pt3d[3].X = (float)area.AxisY.ValueToPosition(chart1.Series["Estimated"].Points[2].YValues[0]);
                    pt3d[3].Z = depth;

                    area.TransformPoints(pt3d);

                    PointF ptF1 = new PointF();
                    PointF ptF2 = new PointF();
                    PointF ptF3 = new PointF();
                    PointF ptF4 = new PointF();
                    PointF ptF5 = new PointF();
                    PointF ptF6 = new PointF();

                    ptF1 = e.ChartGraphics.GetAbsolutePoint(pt3d[0].PointF);
                    ptF3 = e.ChartGraphics.GetAbsolutePoint(pt3d[1].PointF);
                    ptF4 = e.ChartGraphics.GetAbsolutePoint(pt3d[2].PointF);
                    ptF6 = e.ChartGraphics.GetAbsolutePoint(pt3d[3].PointF);

                    ptF2.X = ptF3.X;
                    ptF2.Y = ptF1.Y;

                    ptF5.X = ptF6.X;
                    ptF5.Y = ptF4.Y;

                    // Take Graphics object from chart
                    Graphics graph = e.ChartGraphics.Graphics;

                    graph.DrawLine(new Pen(Color.Black,1), ptF1,ptF2);
                    graph.DrawLine(new Pen(Color.Black,1), ptF2,ptF3);
                    graph.DrawLine(new Pen(Color.Black,1), ptF4,ptF5);
                    graph.DrawLine(new Pen(Color.Black,1), ptF5,ptF6);

                    DrawArrow(graph, Color.Black, ptF3, ptF2, 22.5);
                    DrawArrow(graph, Color.Black, ptF6, ptF5, 22.5);
                }
            }
        }
Example #2
0
		public void TransformPoints (Point3D[] points)
		{
			throw new NotImplementedException ();
		}
Example #3
0
        private double DistanceInLightYears(string remoteSystemName)
        {
            double dist;

            string localSystem;


            localSystem = SystemToMeasureDistancesFrom();

            if (_cachedSystemName != localSystem)
            {
                _cachedRemoteSystemDistances = new Dictionary<string, double>();
                _cachedSystemName = localSystem.ToString();

                _cachedSystemLocation = myMilkyway.getSystemCoordinates(localSystem);
            }


            remoteSystemName = remoteSystemName.ToUpper();

            if (_cachedRemoteSystemDistances.ContainsKey(remoteSystemName))
            {
                dist = _cachedRemoteSystemDistances[remoteSystemName];
            }
            else
            {
                if (!myMilkyway.existSystem(localSystem) || _cachedSystemLocation == null)
                {
                    dist = double.MaxValue;
                }
                else
                {
                    var currentSystemLocation = _cachedSystemLocation;
                    dist = DistanceInLightYears(remoteSystemName, currentSystemLocation);
                    _cachedRemoteSystemDistances.Add(remoteSystemName, dist);
                }
            }

            return dist;
        }
Example #4
0
        private double DistanceInLightYears(string remoteSystemName, Point3D currentSystemLocation)
        {
            double dist;

            Point3D remoteSystemLocation = myMilkyway.getSystemCoordinates(remoteSystemName);

            if (remoteSystemLocation == null)
                return double.MaxValue;

            double xDelta = currentSystemLocation.X - remoteSystemLocation.X;
            double yDelta = currentSystemLocation.Y - remoteSystemLocation.Y;
            double zDelta = currentSystemLocation.Z - remoteSystemLocation.Z;

            dist = Math.Sqrt(Math.Pow(xDelta, 2) + Math.Pow(yDelta, 2) + Math.Pow(zDelta, 2));

            return dist;
        }
        private void chart1_PostPaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e)
        {
            if(sender is ChartArea)
            {
                Series series = chart1.Series["Tasks"];
                // Take Graphics object from chart
                Graphics graph = e.ChartGraphics.Graphics;

                for(int i = 0; i < series.Points.Count; i++)
                {
                    if((i+1) < series.Points.Count && i != 1 && i != 3)
                    {
                        double p1X, p2X, p1Y, p2Y;

                        p1X = series.Points[i].XValue;
                        p2X = series.Points[i+1].XValue;
                        p1Y = series.Points[i].YValues[1];
                        p2Y = series.Points[i+1].YValues[0];

                        float pixelX1 = (float)e.ChartGraphics.GetPositionFromAxis("Default",AxisName.Y,p1Y);
                        float pixelY1 = (float)e.ChartGraphics.GetPositionFromAxis("Default",AxisName.X,p1X);
                        float pixelX2 = (float)e.ChartGraphics.GetPositionFromAxis("Default",AxisName.Y,p2Y);
                        float pixelY2 = (float)e.ChartGraphics.GetPositionFromAxis("Default",AxisName.X,p2X);

                        PointF point1 = PointF.Empty;
                        PointF point2 = PointF.Empty;
                        PointF point3 = PointF.Empty;

                        point1.X = pixelX1;
                        point1.Y = pixelY1;
                        point2.X = pixelX2;
                        point2.Y = pixelY2;

                        // make the middle right-angle point
                        point3.X = pixelX2;
                        point3.Y = pixelY1;

                        // If 3D, we need to transform the 3D points into 2D points
                        if(checkBoxShow3D.Checked)
                        {
                            // Get Z position for this series, and then add half of series depth so that
                            //   custom drawing occurs at the front of the data points
                            float ZPosition = chart1.ChartAreas["Default"].GetSeriesZPosition(series);
                            ZPosition = ZPosition + (float)0.5*(chart1.ChartAreas["Default"].GetSeriesDepth(series));
                            // Create 3D points for the 2D points
                            Point3D[] My3DPoint = new Point3D[3];
                            My3DPoint[0] = new Point3D(point1.X,point1.Y,ZPosition);
                            My3DPoint[1] = new Point3D(point2.X,point2.Y,ZPosition);
                            My3DPoint[2] = new Point3D(point3.X,point3.Y,ZPosition);
                            // Transform so that new 2D points has new X and Y values that take into account the Z position
                            chart1.ChartAreas["Default"].TransformPoints(My3DPoint);
                            point1 = My3DPoint[0].PointF;
                            point2 = My3DPoint[1].PointF;
                            point3 = My3DPoint[2].PointF;
                        }

                        // Convert relative coordinates to absolute coordinates.
                        point1 = e.ChartGraphics.GetAbsolutePoint(point1);
                        point2 = e.ChartGraphics.GetAbsolutePoint(point2);
                        point3 = e.ChartGraphics.GetAbsolutePoint(point3);

                        // Draw connection line
                        graph.DrawLine(new Pen(Color.Black,2), point1,point3);
                        graph.DrawLine(new Pen(Color.Black,2), point3,point2);

                        DrawArrow(graph, Color.Black, point2, point3, 22.5);
                    }
                }

            }
        }