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

  • Home
  • SEARCH
  • 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 3346192
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:16:28+00:00 2026-05-18T01:16:28+00:00

I’ve been trying to do this the whole day. Basically, I have a line

  • 0

I’ve been trying to do this the whole day. Basically, I have a line and a point. I want the line to curve and pass through that point, but I don’t want a smooth curve. I wan’t to be able to define the number of steps in my curve, like so (beware crude mspaint drawing):
curve

And so on. I tried various things, like taking the angle from the center of the initial line and then splitting the line at the point where the angle leads, but I have a problem with the length. I would just take the initial length and divide it by the number of steps I was at, but that wasn’t quite right.

Anyone knows a way to do that?

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-18T01:16:29+00:00Added an answer on May 18, 2026 at 1:16 am

    You would probably need to code this yourself. I think you could do it by implementing a quadratic bezier curve function in code, which can be found here. You decide how fine you want the increments by only solving for a few values. If you want a straight line, only solve for 0 and 1 and connect those points with lines. If you want the one angle example, solve for 0, 0.5, and 1 and connect the points in order. If you want your third example, solve for 0, 0.25, 0.5, 0.75, and 1. It would probably be best to put it in a for loop like this:

    float stepValue = (float)0.25;
    float lastCalculatedValue;
    for (float t = 0; t <= 1; t += stepValue)
    {
        // Solve the quadratic bezier function to get the point at t.
        // If this is not the first point, connect it to the previous point with a line.
        // Store the new value in lastCalculatedValue.
    }
    

    Edit: Actually, it looks like you want the line to pass through your control point. If that is the case, you don’t want to use a quadratic bezier curve. Instead, you probably want a Lagrange curve. This website might help with the equation: http://www.math.ucla.edu/~baker/java/hoefer/Lagrange.htm. But in either case, you can use the same type of loop to control the degree of smoothness.

    2nd Edit: This seems to work. Just change the numberOfSteps member to be the overall number of line segments you want and set the points array appropriately. By the way, you can use more than three points. It will just distribute the total number of line segments across them. But I initialized the array so that the result looks like your last example.

    3rd Edit: I updated the code a bit so you can left click on the form to add points and right click to remove the last point. Also, I added a NumericUpDown to the bottom so you can change the number of segments at runtime.

    public class Form1 : Form
    {
        private int numberOfSegments = 4;
    
        private double[,] multipliers;
        private List<Point> points;
    
        private NumericUpDown numberOfSegmentsUpDown;
    
        public Form1()
        {
            this.numberOfSegmentsUpDown = new NumericUpDown();
            this.numberOfSegmentsUpDown.Value = this.numberOfSegments;
            this.numberOfSegmentsUpDown.ValueChanged += new System.EventHandler(this.numberOfSegmentsUpDown_ValueChanged);
            this.numberOfSegmentsUpDown.Dock = DockStyle.Bottom;
            this.Controls.Add(this.numberOfSegmentsUpDown);
    
            this.points = new List<Point> { 
                new Point(100, 110), 
                new Point(50, 60), 
                new Point(100, 10)};
    
            this.PrecomputeMultipliers();
        }
    
        public void PrecomputeMultipliers()
        {
            this.multipliers = new double[this.points.Count, this.numberOfSegments + 1];
    
            double pointCountMinusOne = (double)(this.points.Count - 1);
    
            for (int currentStep = 0; currentStep <= this.numberOfSegments; currentStep++)
            {
                double t = currentStep / (double)this.numberOfSegments;
    
                for (int pointIndex1 = 0; pointIndex1 < this.points.Count; pointIndex1++)
                {
                    double point1Weight = pointIndex1 / pointCountMinusOne;
    
                    double currentMultiplier = 1;
                    for (int pointIndex2 = 0; pointIndex2 < this.points.Count; pointIndex2++)
                    {
                        if (pointIndex2 == pointIndex1)
                            continue;
    
                        double point2Weight = pointIndex2 / pointCountMinusOne;
                        currentMultiplier *= (t - point2Weight) / (point1Weight - point2Weight);
                    }
    
                    this.multipliers[pointIndex1, currentStep] = currentMultiplier;
                }
            }
        }
    
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
    
            Point? previousPoint = null;
            for (int currentStep = 0; currentStep <= numberOfSegments; currentStep++)
            {
                double sumX = 0;
                double sumY = 0;
                for (int pointIndex = 0; pointIndex < points.Count; pointIndex++)
                {
                    sumX += points[pointIndex].X * multipliers[pointIndex, currentStep];
                    sumY += points[pointIndex].Y * multipliers[pointIndex, currentStep];
                }
    
                Point newPoint = new Point((int)Math.Round(sumX), (int)Math.Round(sumY));
    
                if (previousPoint.HasValue)
                    e.Graphics.DrawLine(Pens.Black, previousPoint.Value, newPoint);
    
                previousPoint = newPoint;
            }
    
            for (int pointIndex = 0; pointIndex < this.points.Count; pointIndex++)
            {
                Point point = this.points[pointIndex];
                e.Graphics.FillRectangle(Brushes.Black, new Rectangle(point.X - 1, point.Y - 1, 2, 2));
            }
        }
    
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
    
            if (e.Button == MouseButtons.Left)
            {
                this.points.Add(e.Location);
            }
            else
            {
                this.points.RemoveAt(this.points.Count - 1);
            }
    
            this.PrecomputeMultipliers();
            this.Invalidate();
        }
    
        private void numberOfSegmentsUpDown_ValueChanged(object sender, EventArgs e)
        {
            this.numberOfSegments = (int)this.numberOfSegmentsUpDown.Value;
            this.PrecomputeMultipliers();
            this.Invalidate();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.