Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: converging point clouds

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default converging point clouds

    i dont know if anyone uses processing here, but im writing some code for simplifying point clouds

    i have written code that makes a random point cloud, and the second part of the code finds the points that are close to each other in a certain tolerance, and deletes them, leaving one point in the center of the deleted group. i cant seem to get the second part of the code to work.
    first part of code :


    void setup() {

    size (400, 400);
    background(255);

    int xnum = 1000;
    int ynum = 1000;
    int[] xarray = new int[xnum];
    int[] yarray = new int[ynum];
    // create random numbers

    for (int i = 0; i < xnum; i++) {
    for (int j = 0; j < xnum; j++) {
    xarray[i] = int(random(0, 400));
    yarray[j] = int(random(0, 400));
    }
    }
    //create points
    for (int i = 0; i < xnum; i++) {
    for (int j = 0; j < xnum; j++) {
    point(xarray[i], yarray[i]);
    }
    }
    }



    Converge(ArrayList<PVector> pts, double tol)
    {
    PVector[] deltaPos = new PVector[pts.length];
    boolean check = false;
    tol = tol * tol;
    for (int i = 0; i < pts.length; i++)
    {
    deltaPos[i] = PVector.sub(LocalCentroid(pts[i], pts, tol), pts[i]);
    if (deltaPos[i].x + deltaPos[i].y > ModelAbsoluteTolerance) // ModelAbsoluteTolerance: to be defined!
    {
    check = true;
    }
    }
    for (int i = 0; i < pts.length; i++)
    {
    pts[i].add(deltaPos[i]);
    }
    return check;
    }

    LocalCentroid(PVector p, ArrayList<PVector> pts, double tolSqr)
    {
    PVector cntr = new PVector(0, 0);
    int count = 0;
    for (int i = 0; i < pts.length; i++)
    {
    PVector testVec = PVector.sub(pts[i], p);
    double lsqr = testVec.x * testVec.x + testVec.y * testVec.y;
    if (lsqr < tolSqr)
    {
    cntr.add(pts[i]);
    count += 1;
    }
    }
    return PVector.div(cntr, count);
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: converging point clouds

    i cant seem to get the second part of the code to work.
    This sounds like a logic problem. Your code probably doesn't follow your algorithm correctly.
    If you know how your algorithm works, you should be able to look at the printed output from printlns of the variables in your code and see where the code is going wrong.
    Add lots of printlns to your code to show how the variables' values are changing. The printout should show you where your code is wrong.

    Since your code does not contain any comments on what its logic is and how it is implementing the algorithm, not many people will be able to help you.

Similar Threads

  1. [SOLVED] Someone point me to the right direction..
    By ineedhelp in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: June 30th, 2011, 10:03 PM
  2. Point constructor
    By upad in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 5th, 2010, 07:34 PM
  3. Projecting a 3d point onto a plane
    By mingming8888 in forum Algorithms & Recursion
    Replies: 8
    Last Post: August 25th, 2010, 11:40 AM
  4. Projecting a 3d point onto a plane
    By mingming8888 in forum Java Theory & Questions
    Replies: 8
    Last Post: August 25th, 2010, 11:40 AM
  5. how do i use point 3d?
    By antrax in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 05:13 PM