How to get Length of Graphics.DrawLines (Points) in c#

Hi,

oGraphics = e.Gragpics
 Point[] pntLines = new Point{(323,449), (324, 449), (325, 448), (327,444), (327,443) }
            oGraphics.DrawLines(oPen, pntLines);
   oGraphics.DrawString("TestLine", Font,  Brushes.Red,  MiddleLineofPntLines?????)

How can get exactly middle of Point of pntLines.

Thanks..


     
narlasridharAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kaylanreilorCommented:
BTW I think you have used the System.Windows.Shapes.Polygon class accordingly with the Gragpics.DrawPolygon method to draw this shape. With this Polygon class you'll get some helpful properties like Height or Width...
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawpolygon.aspx
http://msdn.microsoft.com/en-us/library/system.windows.shapes.polygon.aspx
Anyway, as far as I know this is not a C# problem but a mathematical issue. I think you have to calculate it by yourself. I suppose that you can calculte the average X coordinates and the average of Y coordinates, don't you ?
0
jgordosCommented:
You're asking how to compute the centroid.

This sounds like a homework problem, so i can't directly answer the "how"... but I can provide some tips...

The center of a polygon is the mean of all the X,Y coordinates...

Check the wikipedia regarding CENTROID

But, to compute the mean, do the following

For all the X in the list, sum the values...
For all the Y in the list, sum the values...
Divide by the number of point pairs in the list...

-john

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
narlasridharAuthor Commented:
hi igordos,

Thanks verymuch helping this solution.   Still i am looking for a Trigonometry function to do this in .net
The way i did....

Assuming strait line from minimum point to maximum point.  and calculating the  middle point by following formula.

   (x1 - X-max point, x2  - X-Mini Point, y1 - Y-MaxPoint, y2 - Y-Miniumum Point ) in the array...
so MiddlePoint = ((x1-x2) / 2 + x1, (y1-y2) / 2)
-------------------------E x a m p l e ---------------------------------------------------------------------------
            Point MinPoint = arrPoints[0];
            Point MaxPoint = arrPoints[arrPoints.Length - 1];
            Point MiddlePoint = new Point((int)(MaxPoint.X - MinPoint.X) / 2 + MinPoint.X,
                    (int)(MaxPoint.Y - MinPoint.Y) / 2 + MinPoint.Y);

            Point mMaxPoint = new Point(0, 0), mMinPoint = new Point(0, 0), mMidPoint = new Point(0, 0);
            int a = 0;
            for (int i = 0; i < arrPoints.Length; i++)
            {
                if (arrPoints[i].X < MiddlePoint.X && i != arrPoints.Length - 2)
                    continue;
                else
                {
                    if (a == 0)
                    {
                        mMinPoint = arrPoints[i - 1];
                        a++;
                    }
                    else
                    {
                        mMaxPoint = arrPoints[i - 1];
                        mMidPoint = new Point((int)(mMaxPoint.X - mMinPoint.X/2 +  mMinPoint.X) ,
                               (int)(mMaxPoint.Y - mMinPoint.Y)/2 + mMinPoint.Y);
                        break;
                    }
                }
            }
           
            Graphics g = pictureBox1.CreateGraphics();
            g.DrawLines(new Pen(Brushes.Red), arrPoints);
            g.DrawString("Test", this.Font, new SolidBrush(Color.Tomato), mMidPoint);
 
 --------------------------------------


   
0
jgordosCommented:
I have no idea why you're closing it.

Can you supply some details?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.