Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:35:31+00:00 2026-05-14T09:35:31+00:00

I am drawing graphs into a WinForms Picturebox. Now I am searching for a

  • 0

I am drawing graphs into a WinForms Picturebox. Now I am searching for a possibility to ‘duplicate’ a line (an array of points), so that the two resulting lines are positioned a fixed distance away from the original one. Like in this picture, I have the red line and want to get the black ones:

Picture of lines http://img227.imageshack.us/img227/2341/linesb.png

I thought about just moving the line a few pixels up/right/up-right, but that leads to strange overlapping lines.

Is there any other approach that does what I want? Any ideas would be greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:35:32+00:00Added an answer on May 14, 2026 at 9:35 am

    I have created a function that does exactly what you need a few months ago as a part of a graph layouting algorithm. I wrote that in python and PyQt. I just pasted the code here at codepad. That should be very easily translateable to c#.

    Update:

    Translated it one-to-one from my python snippet (Love to do that graphics stuff 🙂 ). As my original code was designed for more than two output lines, I just took that into the c# version as well. For two black lines being 20 pixels away from the red one, just pass width = 40 and num = 2. The returned jagged array represents an array of lines (outer array), with each line represented by an array of points (inner).

    public PointF[][] MultiplyLine(PointF[] line, int width, int num)
    {
        if (num == 1) return new PointF[][] { line };
        if (num < 1) throw new ArgumentOutOfRangeException();
        if (line.Length < 2) return Enumerable.Range(0, num)
                      .Select(x => line).ToArray();
    
        Func<float, float, PointF> normVec = (x, y) => {
            float len = (float)Math.Sqrt((double)(x * x + y * y));
            return len == 0 ? new PointF(1f, 0f) : new PointF(x / len, y / len);
        };
    
        PointF[][] newLines = Enumerable.Range(0, num)
                      .Select(x => new PointF[line.Length]).ToArray();
    
        float numinv = 1f / (float)(num - 1), cor = 0f;
        PointF vec1 = PointF.Empty, vec2 = PointF.Empty, vec3 = PointF.Empty;
    
        int j = -1, i = -1;
        foreach (PointF p in line)
        {
            bool first = j == -1, last = j == line.Length - 2; j++;
    
            if (!last)
                vec1 = normVec(line[j + 1].Y - p.Y, -line[j + 1].X + p.X);
            if (!first)
                vec2 = normVec(-line[j - 1].Y + p.Y, line[j - 1].X - p.X);
            if (!first && !last)
            {
                vec3 = normVec(vec1.X + vec2.X, vec1.Y + vec2.Y);
                cor = (float)Math.Sin((Math.PI - 
                      Math.Acos(vec1.X * vec2.X + vec1.Y * vec2.Y)) / 2);
                cor = cor == 0 ? 1 : cor;
                vec3 = new PointF(vec3.X / cor, vec3.Y / cor);
            }
    
            i = -1;
            foreach (PointF[] newLine in newLines)
            {
                i++; cor = (float)width * ((float)i * numinv - 0.5f);
                vec1 = first ? vec1 : last ? vec2 : vec3;
                newLine[j] = new PointF(vec1.X * cor + p.X, vec1.Y * cor + p.Y);
            }
        }
    
        return newLines;
    }
    

    To try it out I took this small sample (The same sample as in my PyQt code):

    PointF[] pts = new PointF[] { 
        new PointF(100f, 100f), new PointF(300f, 200f), 
        new PointF(500f, 200f), new PointF(300f, 500f), 
        new PointF(600f, 450f), new PointF(650f, 180f), 
        new PointF(800f, 180f), new PointF(800f, 500f), 
        new PointF(200f, 700f)
    };
    
    pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
    using(Graphics g = Graphics.FromImage(pictureBox1.Image)){
        g.DrawLines(new Pen(Color.Red), pts);
    
        foreach (PointF[] line in MultiplyLine(pts, 80, 14))
            g.DrawLines(new Pen(Color.Black), line);
    }
    

    Which resulted in this graphic:

    outlines around line http://img41.imageshack.us/img41/8606/lines2.th.png

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Google visualization for drawing graphs into my website. This involves
I'm drawing graphs with force-directed layout, and the problem is that the created graphs
I've looked at Microsoft GLEE (non-commerical use) and other libraries for drawing graphs, but
I am drawing multiple graphs via a shell script in gnuplot. The graphs are
I want to use core-plot for drawing line graph dynamically. data won't come at
I've discovered flot for jquery for drawing nice graphs. But I can't parse the
I'm writing android app, which drawing 4 graphs in 1 plot. Graph data is
i use gpgraph library for charts drawing. i need to dinamicaly create graphs, so
I am using the Core Plot library for drawing graphs on the iOS. I
I am drawing a graph on a <canvas> that requires expensive calculations. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.