Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Parallel lines & rounded line

Parallel lines & rounded line

Scheduled Pinned Locked Moved C#
helptutorial
12 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A AlexB47

    Hi ALL, I have a list of point coordinates (x,y) to draw a line. The line is curve. I need to draw 2 parallel line, at left and at right of this line. My scope is to draw a rounded line of intere line. Help me please, with example. Thanks.

    Alex

    D Offline
    D Offline
    dan sh
    wrote on last edited by
    #3

    AlexB47 wrote:

    The line is curve

    Is it a curve or a straight line?

    AlexB47 wrote:

    My scope is to draw a rounded line of intere line

    You mean circle? Graphics class has methods like DrawLine, DrawCurve and DrawEllipse. Read about them and you should be able to do this. Make sure you do your drawing in the Paint event and use PaintEventArgs.Graphics object to draw. Drawing the parallel lines should be simple: get the X coordinate of the "end" from where you need to draw the parallel line. Then with same X coordinate, just change the Y and draw the line. Choice of Y coordinate would depend on the length of the parallel line segment you need to draw.

    50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

    A 1 Reply Last reply
    0
    • D dan sh

      AlexB47 wrote:

      The line is curve

      Is it a curve or a straight line?

      AlexB47 wrote:

      My scope is to draw a rounded line of intere line

      You mean circle? Graphics class has methods like DrawLine, DrawCurve and DrawEllipse. Read about them and you should be able to do this. Make sure you do your drawing in the Paint event and use PaintEventArgs.Graphics object to draw. Drawing the parallel lines should be simple: get the X coordinate of the "end" from where you need to draw the parallel line. Then with same X coordinate, just change the Y and draw the line. Choice of Y coordinate would depend on the length of the parallel line segment you need to draw.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      A Offline
      A Offline
      AlexB47
      wrote on last edited by
      #4

      curved line. I have to build 2 parallel lines of a GPS track (so curved path). Building a sort of lane of the road. :)

      Alex

      R 1 Reply Last reply
      0
      • A AlexB47

        curved line. I have to build 2 parallel lines of a GPS track (so curved path). Building a sort of lane of the road. :)

        Alex

        R Offline
        R Offline
        Rob Philpott
        wrote on last edited by
        #5

        That's tricky. You can only draw lines on the left and the right when the road runs north to south. With east to west, you'd need to draw them top and bottom. I think you're going to be need some trigonometry to do this. You could probably cheat by drawing a thick line and overlaying a thin line and let windows do the rounding of intersections. Are you in GDI or WPF?

        Regards, Rob Philpott.

        A 1 Reply Last reply
        0
        • R Rob Philpott

          That's tricky. You can only draw lines on the left and the right when the road runs north to south. With east to west, you'd need to draw them top and bottom. I think you're going to be need some trigonometry to do this. You could probably cheat by drawing a thick line and overlaying a thin line and let windows do the rounding of intersections. Are you in GDI or WPF?

          Regards, Rob Philpott.

          A Offline
          A Offline
          AlexB47
          wrote on last edited by
          #6

          in GDI (I use DrawLine etc...).

          Alex

          R 1 Reply Last reply
          0
          • A Anurag Gandhi

            Could you please make it clear what do you want to do?

            AlexB47 wrote:

            My scope is to draw a rounded line

            Rounded line? Did you mean a Curve??

            Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.

            A Offline
            A Offline
            AlexB47
            wrote on last edited by
            #7

            read below...

            Alex

            1 Reply Last reply
            0
            • A AlexB47

              in GDI (I use DrawLine etc...).

              Alex

              R Offline
              R Offline
              Rob Philpott
              wrote on last edited by
              #8

              Ok, using the 'hack' mentioned above, create a new windows forms application in visual studio, and add the following in form1.cs

              protected override void OnPaint(PaintEventArgs e)
              {
              base.OnPaint(e);

              GraphicsPath p = new GraphicsPath(FillMode.Alternate);
              p.AddLine(0, 0, 50, 50);
              p.AddLine(50, 50, 60, 50);
              p.AddLine(60, 50, 60, 60);
              p.AddLine(60, 60, 90, 130);
              
              Pen pen = new Pen(Brushes.Black, 10);
              Pen p2 = new Pen(Brushes.White, 4);
              e.Graphics.DrawPath(pen, p);
              e.Graphics.DrawPath(p2, p);
              

              }

              That's one approach...

              Regards, Rob Philpott.

              L M A 4 Replies Last reply
              0
              • R Rob Philpott

                Ok, using the 'hack' mentioned above, create a new windows forms application in visual studio, and add the following in form1.cs

                protected override void OnPaint(PaintEventArgs e)
                {
                base.OnPaint(e);

                GraphicsPath p = new GraphicsPath(FillMode.Alternate);
                p.AddLine(0, 0, 50, 50);
                p.AddLine(50, 50, 60, 50);
                p.AddLine(60, 50, 60, 60);
                p.AddLine(60, 60, 90, 130);
                
                Pen pen = new Pen(Brushes.Black, 10);
                Pen p2 = new Pen(Brushes.White, 4);
                e.Graphics.DrawPath(pen, p);
                e.Graphics.DrawPath(p2, p);
                

                }

                That's one approach...

                Regards, Rob Philpott.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #9

                yep. that is what I would try, intuitively I would use odd line widths though. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
                [The QA section does it automatically now, I hope we soon get it on regular forums as well]


                1 Reply Last reply
                0
                • R Rob Philpott

                  Ok, using the 'hack' mentioned above, create a new windows forms application in visual studio, and add the following in form1.cs

                  protected override void OnPaint(PaintEventArgs e)
                  {
                  base.OnPaint(e);

                  GraphicsPath p = new GraphicsPath(FillMode.Alternate);
                  p.AddLine(0, 0, 50, 50);
                  p.AddLine(50, 50, 60, 50);
                  p.AddLine(60, 50, 60, 60);
                  p.AddLine(60, 60, 90, 130);
                  
                  Pen pen = new Pen(Brushes.Black, 10);
                  Pen p2 = new Pen(Brushes.White, 4);
                  e.Graphics.DrawPath(pen, p);
                  e.Graphics.DrawPath(p2, p);
                  

                  }

                  That's one approach...

                  Regards, Rob Philpott.

                  M Offline
                  M Offline
                  Martin 0
                  wrote on last edited by
                  #10

                  Rob Philpott wrote:

                  That's one approach...

                  Which is nice, apart from the fact that you are not .Dispose() the GraphicsPath and Pen instances you created.

                  All the best, Martin

                  1 Reply Last reply
                  0
                  • R Rob Philpott

                    Ok, using the 'hack' mentioned above, create a new windows forms application in visual studio, and add the following in form1.cs

                    protected override void OnPaint(PaintEventArgs e)
                    {
                    base.OnPaint(e);

                    GraphicsPath p = new GraphicsPath(FillMode.Alternate);
                    p.AddLine(0, 0, 50, 50);
                    p.AddLine(50, 50, 60, 50);
                    p.AddLine(60, 50, 60, 60);
                    p.AddLine(60, 60, 90, 130);
                    
                    Pen pen = new Pen(Brushes.Black, 10);
                    Pen p2 = new Pen(Brushes.White, 4);
                    e.Graphics.DrawPath(pen, p);
                    e.Graphics.DrawPath(p2, p);
                    

                    }

                    That's one approach...

                    Regards, Rob Philpott.

                    A Offline
                    A Offline
                    AlexB47
                    wrote on last edited by
                    #11

                    Thanks.. I try with your solutions ... ;)

                    Alex

                    1 Reply Last reply
                    0
                    • R Rob Philpott

                      Ok, using the 'hack' mentioned above, create a new windows forms application in visual studio, and add the following in form1.cs

                      protected override void OnPaint(PaintEventArgs e)
                      {
                      base.OnPaint(e);

                      GraphicsPath p = new GraphicsPath(FillMode.Alternate);
                      p.AddLine(0, 0, 50, 50);
                      p.AddLine(50, 50, 60, 50);
                      p.AddLine(60, 50, 60, 60);
                      p.AddLine(60, 60, 90, 130);
                      
                      Pen pen = new Pen(Brushes.Black, 10);
                      Pen p2 = new Pen(Brushes.White, 4);
                      e.Graphics.DrawPath(pen, p);
                      e.Graphics.DrawPath(p2, p);
                      

                      }

                      That's one approach...

                      Regards, Rob Philpott.

                      A Offline
                      A Offline
                      AlexB47
                      wrote on last edited by
                      #12

                      Hello, I have another problem. Is there a way to avoid that the circuit is redrawn below? I to draw the current point that moves, use the DrawEllipse function (current position). How can I avoid soiling the circuit with all subsequent drawEllipse? Thanks.

                      Alex

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups