Page 1 of 1

Drawing an arrow at the end of a line using Graphics3D

Posted: Wed Feb 25, 2009 8:03 pm
by 14049416
I and wanting to draw a line with a very pronounced arrow using the Graphics3D object. I tried using the g.Arrow method but when I specify a 7x7 pixel arrow the line is real thick. Why? And is there another way of doing this? I cannot use a DrawLine in this case as I am doing all my drawing in the AfterDraw event.

Thanks,
Kevin

Posted: Thu Feb 26, 2009 10:14 am
by 10050769
Hi WD_Gordon,


We doesn't understand exactly do you want. Please, could you send us a simple example project we can run "as-is" to reproduce the problem here?
You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page. Or it tells you what you want exactly.

On the other hand, TeeChart have ArrowSeries. This draw arrows using two points for example: x0,y0 (p0), x1 ,y1 (p1). Also you can see in TeeChart .NET demo arrow example AllFeatures/Welcome !\Chart styles\Standard\Arrow example, could be interesting for you.

Thanks

Posted: Thu Feb 26, 2009 2:36 pm
by 14049416
Hi Sandra,

I don't need the ArrowSeries, all I am doing is drawing in the AfterDraw event. I uploaded an image named Fibonacci_Arrow.JPG, to show you what I am talking about.

The arrow at the top was drawn using the arrow method as follows:
g.Arrow(true, new Point(topLeft.X, topLeft.Y), new Point(bottomRight.X, bottomRight.Y), 10, 10, 0);

As you can see it paints a thick line as well.

Thanks,
Kevin

Posted: Fri Feb 27, 2009 10:22 am
by 10050769
Hi Kevin,

We suggest a similar code as next example, in AfterDraw event:

Code: Select all

        private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
   
            Point p1 = new Point(tChart1.Chart.ChartRect.Left,tChart1.Chart.ChartRect.Top);
            Point p2 = new Point(tChart1.Chart.ChartRect.Right, tChart1.Chart.ChartRect.Bottom);
            Point p3 = new Point(tChart1.Chart.ChartRect.Right-6, tChart1.Chart.ChartRect.Bottom -4) ;
            g.Brush.Color = Color.Black;
            g.Line(p1, p2);
            g.Arrow(true,p3,p2, 10, 10, 0);


        }
Hope this helps!

Posted: Fri Feb 27, 2009 12:44 pm
by 14049416
Hi Sandra,

The only problem with your example is you are assuming the the line is running at a 45° angle. The user can size this object so the line can be drawn in all directions at any degree. Any suggestions?

Thanks,
Kevin

Posted: Tue Mar 03, 2009 11:14 am
by yeray
Hi Kevin,

Here you have an example of how you could draw a thin line with a big head:

Code: Select all

public partial class Form1 : Form
    {
        bool DrawLine;
        Point headStartPoint, fromPoint, toPoint;

        public Form1()
        {
            InitializeComponent();

            InitializeChart();
        }

        private void InitializeChart()
        {
            chartController1.Chart = tChart1;

            fromPoint = new Point();
            toPoint = new Point();
            headStartPoint = new Point();
            DrawLine = false;

            tChart1.Zoom.Allow = false;
            tChart1.Aspect.View3D = false;

            tChart1.MouseDown +=new MouseEventHandler(tChart1_MouseDown);
            tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
            tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
            tChart1.AfterDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
        }

        void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                fromPoint.X = e.X;
                fromPoint.Y = e.Y;
                DrawLine = true;
            }
        }

        void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                DrawLine = false;
            }
        }

        void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            if (DrawLine)
            {
                toPoint.X = e.X;
                toPoint.Y = e.Y;
                tChart1.Refresh();
            }
        }

        void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (DrawLine)
            {
                g.Brush.Color = Color.Black;
                g.Line(fromPoint, toPoint);

                int dx = toPoint.X - fromPoint.X;
                int dy = fromPoint.Y - toPoint.Y;

                if (Math.Sqrt(dx * dx + dy * dy) > 7)
                {
                    if (dx == 0)
                    {
                        if (dy > 0)
                        {
                            headStartPoint.X = toPoint.X;
                            headStartPoint.Y = toPoint.Y + 6;
                        }
                        else
                        {
                            headStartPoint.X = toPoint.X;
                            headStartPoint.Y = toPoint.Y - 6;
                        }
                    }
                    else
                    {
                        headStartPoint.X = (int)(toPoint.X - (6 * Math.Cos(Math.Atan2(dy, dx))));
                        headStartPoint.Y = (int)(toPoint.Y + (6 * Math.Sin(Math.Atan2(dy, dx))));
                    }
                    g.Arrow(true, headStartPoint, toPoint, 10, 10, 0);
                }
            }
        }
    }