|
|
Austin
 Joined: Apr 2008
Posts: 32
|
 |
Reply #1 Posted on: May 30, 2008, 12:55:02 AM |
|
|
|
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)); }
|
|
|
Josh @ Dreamland
Prince of all Goldfish
 Joined: Feb 2008
Posts: 2,950
|
 |
Reply #2 Posted on: September 04, 2008, 11:45:33 PM |
|
|
|
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.
|
|
|
|
Post made October 22, 2008, 03:32:26 PM was deleted at the author's request.
|
score_under
 Joined: Aug 2008
Posts: 308
|
 |
Reply #4 Posted on: October 22, 2008, 06:14:57 PM |
|
|
Oh dear, imaginary numbers. Quote#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, Quote#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?
|
|
|
sprintf()
Past Contributor Joined: Apr 2008
Posts: 72
|
 |
Reply #5 Posted on: October 22, 2008, 07:56:03 PM |
|
|
|
All square numbers are positive.
|
|
|
|
|
|
Post made November 15, 2008, 07:38:24 PM was deleted at the author's request.
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #8 Posted on: November 16, 2008, 02:57:23 AM |
|
|
|
As far as I know, C++ doesn't have an i constant. Would be cool, though.
|
|
|
score_under
 Joined: Aug 2008
Posts: 308
|
 |
Reply #9 Posted on: November 16, 2008, 11:47:57 AM |
|
|
|
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++)
|
|
|
Josh @ Dreamland
Prince of all Goldfish
 Joined: Feb 2008
Posts: 2,950
|
 |
Reply #10 Posted on: November 16, 2008, 01:59:04 PM |
|
|
|
XD @ i constant
Nah. C++ would just kill your game for you. ^_^
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #11 Posted on: November 18, 2008, 12:16:57 AM |
|
|
|
Not actually an "i" variable, but support for imaginary numbers. You could always just do sqrt(-1). =P
|
|
|
ludamad
 Joined: May 2008
Posts: 1,256
|
 |
Reply #12 Posted on: November 22, 2008, 08:53:22 PM |
|
|
|
RetroX: #include <Complex>
|
|
|
RetroX
Master of all things Linux
 Joined: Apr 2008
Posts: 1,055
|
 |
Reply #13 Posted on: November 23, 2008, 03:40:34 PM |
|
|
Wait, C++ has a library for that? O_O EDIT: Holy shit. That is awesome. 
|
|
|
|