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

1. 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++)
{
}
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)
{
count += 1;
}
}
return PVector.div(cntr, count);
}

2. Re: converging point clouds

i cant seem to get the second part of the code to work.