ENIGMA Forums
Contributing to ENIGMA => Function Peer Review => Topic started by: MrJackSparrow2 on May 29, 2008, 04:58:02 pm
-
I'm sure you already have this, but i'm trying to help. :)
#include <math.h>
double point_distance(double x1,double y1,double x2,double y2)
{
return (double) sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) );
}
-
And for two 3D points (I didn't define the types because I am not sure what you use):
d3d_point_distance(x1,y1,z1,x2,y2,z2) {
return sqrt(sqr(x1-x2)+sqr(y1-y2)+sqr(z1-z2));
}
-
The former has existed since R1, but the latter doesn't exist in 'other programs,' and I prolly won't add it until I actually do some 3D.
-
I'm sure you already have this, but i'm trying to help. :)
#include <math.h>
double point_distance(double x1,double y1,double x2,double y2)
{
return (double) sqrt( ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) );
}
That would be uneffecient. Why not:
#include <math.h>
double point_distance(double x1,double y1,double x2,double y2)
{
int x_diff,y_diff;
x_diff = x2-x1;
y_diff = y2-y1;
return (double)sqrt((x_diff*x_diff)+(y_diff*y_diff));
}
Not sure how old this topic is, though xD
EDIT:
Sorry, didn't notice Josh's post.
-
Oh dear, imaginary numbers.
#include <math.h>
double point_distance(double x1,double y1,double x2,double y2)
{
int x_diff,y_diff;
x_diff = x2-x1;
y_diff = y2-y1;
return (double)sqrt((x_diff*x_diff)+(y_diff*y_diff));
}
If I were to measure the distance from point (4,4) to point (0,0) without any checking on my part, this would cause a huge error as the numbers would suddenly mysteriously appear in the complex plane ;)
Off the top of my head,
#include <math.h>
double point_distance(double x1,double y1,double x2,double y2)
{
int x_diff,y_diff;
x_diff = abs(x2-x1);
y_diff = abs(y2-y1);
return (double)sqrt((x_diff*x_diff)+(y_diff*y_diff));
}
That should work better, right?
-
All square numbers are positive.
-
All square numbers are positive.
Of course I was... testing.
-
All square numbers are positive.
Of course I was... testing.
:D
-
As far as I know, C++ doesn't have an i constant. Would be cool, though.
-
If it had an "i" constant, then 99% of c++ programs would be broken.
It's hard to find a C++ prog that does NOT contain something similar to:
for(i=0;i<size;i++)
-
XD @ i constant
Nah. C++ would just kill your game for you. ^_^
-
Not actually an "i" variable, but support for imaginary numbers. You could always just do sqrt(-1). =P
-
RetroX: #include <Complex>
-
Wait, C++ has a library for that? O_O
EDIT: Holy shit. That is awesome. :D