We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Pan-Dimensional Distance Measurement
Page Index Toggle Pages: 1
Pan-Dimensional Distance Measurement (Read 269 times)
Pan-Dimensional Distance Measurement
Sep 21st, 2006, 9:33pm
 
I'm working on the AStar gig and I've decided I will likely need an arbitrary number of dimensions (this allows you to take a standard space and make it hard to move through - rather like climbing a mountain on a 2D plane or swimming through custard on a 3D plane).

I would like to know if I've got my maths right or if I'm slowing procedures down too much.

What follows is a stripped down view of the Node class - it allows Nodes to have different dimensions. When it has to calculate a discrepancy in dimensions it assumes the missing dimensions are flat (compare cube to plane).
Code:

Node a, b;
void setup(){
a = new Node(new float [] {10, 10, 10});
b = new Node(new float [] {20, 20});
println(a.dist(b));
}
class Node{
float [] locale;
Node(float [] locale){
this.locale = locale;
}
float dist(Node b){
int iterations = max(locale.length, b.locale.length);
float squaredSum = 0.0;
for(int i = 0; i < iterations; i++){
squaredSum += sq((i < b.locale.length ? b.locale[i] : 0.0) - (i < locale.length ? locale[i] : 0.0));
}
return sqrt(squaredSum);
}
}

I'm sure the equation is right but I can't tell. Plus those inline conditionals have me worried too.

Please can someone tell me?
Page Index Toggle Pages: 1