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 7843765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:39:19+00:00 2026-06-02T16:39:19+00:00

I’m having difficulty formulating this elegantly into an algorithm. So I have a given

  • 0

I’m having difficulty formulating this elegantly into an algorithm.

So I have a given a straight-edged shape (ie. square, though in the end shape doesn’t matter only endpoints). I get the bounding endpoints on a Cartesian coordinate system : (2,-2) (2,2) (-2,2) (-2,-2)

I’m given an arbitrary number of points (ie. 7) and I want to spread these points (x,y) uniformly along the edges of the shape (in this case a square).

My current idea is to get the total length of all endpoints, divide this by the number of points to get a segment length (which I then normalize against an edge). Then I go from endpoint to endpoint finding the point between by this amount and accrue the normalized slice, when this total exceeds 1.0 I iterate the endpoint and take the remainder and start from there…or something like that.

Could someone help me put this into an algorithm (C# preferably) or if you have a better solution please do tell. I’d imagine there is a sorting or distribution/division algorithm that could have the same affect, but I couldn’t find any. I hope this isn’t blatantly obvious.

  • 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-06-02T16:39:20+00:00Added an answer on June 2, 2026 at 4:39 pm

    How general does this need to be? Also, how are representing your shape, and the points? Your algorithm seems to be ok; do you need help turning it into code?


    Alrighty, here’s something i came up with.
    Notes on the code:

    • The distance method takes two Points and returns the distance between them.
    • The normalize method takes two points and returns the normal vector pointing from the first point to the second point.
    • The Point class has the multiply method which multiplies the point by a scalar
    • The Point class has float (or double) precision

    I’m using the Point class to represent vectors by the way.

    I haven’t tested this, so there might be bugs. There might be issues with how this algorithm handles exact regions (e.g. your square with exactly 4 points on it). Let me know if there are issues or if you have any questions! 🙂

    Point[] shapePoints; //already initialized
    int numPoints; //already initialized
    Point[] retPoints = new Point[numPoints];
    int totalLength;
    for(int i = 1; i < shapePoints.length; i++){
        totalLength += distance(shapePoints[i], (shapePoints[i-1]));
    }
    float segLength = ((float) totalLength) / numPoints);
    Point currShape = shapePoints[0];
    Point nextShape = shapePoints[1];
    Point prev = currShape;
    int counter = 2;
    while(numPoints > 0){
        Point norm = normalize(new Point(nextShape.x - currShape.x, nextShape.y - currShape.y));
        if(distance(nextShape, prev) < segLength){
            int tempLength = segLength;
            tempLength -= distance(nextShape, prev);
            currShape = nextShape;
            nextShape = shapePoints[counter];
            counter ++;
            norm = normalize(new Point(nextShape.x - currShape.x, nextShape.y - currShape.y));
            norm.multiply(tempLength);
        }
        else{
            norm.multiply(segLength);
        }       
        retPoints[numPoints - 1] = norm;
        prev = retPoints[numPoints - 1];
        numPoints --;
    }
    

    Point normalize(Point p){
        int scale = Math.sqrt(p.x * p.x + p.y * p.y);
        p.x = p.x / scale;
        p.y = p.y / scale;
        return p;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and

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.