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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:00:51+00:00 2026-05-30T18:00:51+00:00

I have an array of points A,B,C,D,E…N which when connected make a path. How

  • 0

I have an array of points A,B,C,D,E…N which when connected make a path.

enter image description here

How can i divide this path to equal chunks and get position of each chunk XY ?

EDIT : As user Hedja suggested i have created function to process this problem, but i cannot detect situation where chunk is splitted on two subpaths

public ArrayList<PointF> getPositions(ArrayList<PointF> mInput,float mChunkSize){
    ArrayList<PointF> mResult = new ArrayList<PointF>();
    float mModulo = 0f;
    for (int i = 0;i<mInput.size()-1;i++){
        //distance to next
        float mDistanceAB = MyGameMath.distance(mInput.get(i).x, mInput.get(i).y,mInput.get(i+1).x,mInput.get(i+1).y);
        //how many parts will fit 
        float mCountParts = (float) (mDistanceAB/mChunkSize); //how much parts will fit 
        //if distance is greater than chunk size 
        if (Math.abs(mDistanceAB)>=mChunkSize) {
            Log.i("Chunk","Index "+(i)+" -> "+(i+1)+" = "+mCountParts+", rest="+mModulo);
            float dx = mInput.get(i+1).x-mInput.get(i).x;
            float dy = mInput.get(i+1).y-mInput.get(i).y;
            float ux = dx/mDistanceAB;
            float uy = dy/mDistanceAB;
            for (int y=0;y<=mCountParts;y++){
                //for every part
                float nx = mInput.get(i).x+ux*mChunkSize*y;
                float ny = mInput.get(i).y+uy*mChunkSize*y;
                                    //Log.i("Chunk","at:"+nx+","+ny);
                mResult.add(new PointF(nx, ny));
            }
        } 
        mModulo = mDistanceAB%mChunkSize; //how much left from previous subpath
    }
    return mResult;
}
  • 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-30T18:00:52+00:00Added an answer on May 30, 2026 at 6:00 pm

    So I assume you have something similar to this where Point is an object with attributes x and y.

    Point[] points = new Points[]{ //Your Points }
    List<Point> chunkedPoints = new ArrayList<Point>();
    

    I also assume by “equal chunks” you mean the distance of each path.

    First you’ll iterate through the array, as you won’t need to calculate the “next point” after the last point, you can add it at the end.:

    for(int i = 0; i < points.length-1; i++) { //Skip the last element
        //chunking here
    }
    chunkedPoints.add(points[points.length-1]); //Add the last element
    

    You’ll need to find the Unit Vector, that is, the direction you travel to get to the next point. So first you need to get the difference in x and y from one point and the next:

    double dx = point[i].x - point[i+1].x;
    double dy = point[i].y - point[i+1].y;
    

    Then the distance from that point to the next (simple Pythagoras):
    double distance = Math.sqrt(dx*dx+dy*dy);

    The unit vector can now be calculated

    double ux = dx/distance;
    double uy = dy/distance;
    

    So now you know where to travel, you need to specify how far you want to travel along it, I’ll call this CHUNK_SIZE.

    double nx = point[i].x + ux*CHUNK_SIZE;
    double ny = point[i].y + uy*CHUNK_SIZE;
    

    nx and ny is the co-ordinate of your new point. However, you need to check if you’ve passed the next point so that you can stop. Your problem doesn’t specify what you do when you reach an end of a subpath without travelling the chunk size so I’ll assume you simply stop at it, so the code becomes:

    double nx = point[i].x;
    double ny = point[i].y;
    for(
        //This part can be tidier
        int count = 0;
        count < CHUNK_SIZE && nx+ux != points[i+1].x && ny+uy != points[i+1].y;
        count++
    ) {
        nx += ux;
        ny += uy;
    }
    Point newPoint = new Point(nx, ny);
    

    Now you have your new Point, you can start from there, aim for the same point as before or if it’s the same as the next point, start from the point after that. So your loop is now something like

    chunkedPoints.add(points[0]);
    for(int i = 0; i < points.length-1; i++) { //Skip the last element
        Point newPoint;
        do {
            //chunking
            newPoint = new Point(nx, ny);
            chunkedPoints.add(newPoint);
        } while(!newPoint.equals(points[i+1]));
    }
    chunkedPoints.add(points[points.length-1]); //Add the last element
    

    Hope that helped.

    I haven’t tested this, but I’ve done something very similar in the past, so it should work.

    EDIT: Okay, I’ve seen your edit and honestly have no idea what your question is asking. Sorry.

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

Sidebar

Related Questions

I have two questions: 1) How can I make an array which points to
Let's say I have an array of LatLng points which make up a polygon.
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have an array of points, of which(points) I know the coordinates(in my coordinate
I am working with delphi. I have an array of points which are continues
Total blank on how to do this. I have an array points and an
I have an array of points PArr [0..3] which correspond to the rectangle points
I have a two dimensional array of points, which constitute a map. The black
I have an array of points. I want to know if this array of
I have a huge array of 2D points (about 3 millions of pairs), which

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.