# ENIGMA Development Environment

 Pages: 1
 Author Topic: The formula for finding point_distance.  (Read 6494 times)
MrJackSparrow2
 Posted on: May 29, 2008, 04:58:02 PM

Joined: Apr 2008
Posts: 35

I'm sure you already have this, but i'm trying to help.

Code: [Select]
`#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)) );}`
 Logged
Austin
 Reply #1 Posted on: May 29, 2008, 07:55:02 PM

Location: Florida
Joined: Apr 2008
Posts: 32

And for two 3D points (I didn't define the types because I am not sure what you use):
Code: [Select]
`d3d_point_distance(x1,y1,z1,x2,y2,z2) {    return sqrt(sqr(x1-x2)+sqr(y1-y2)+sqr(z1-z2));}`
 Logged
Josh @ Dreamland
 Reply #2 Posted on: September 04, 2008, 06:45:33 PM

Prince of all Goldfish

Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2956

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.
 Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Post made October 22, 2008, 10:32:26 AM was deleted at the author's request.
score_under
 Reply #4 Posted on: October 22, 2008, 01:14:57 PM

Joined: Aug 2008
Posts: 308

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?
 Logged
sprintf()
 Reply #5 Posted on: October 22, 2008, 02:56:03 PM

"Past Contributor"
Location: S. Wales
Joined: Apr 2008
Posts: 72

All square numbers are positive.
 Logged
score_under
 Reply #6 Posted on: October 22, 2008, 03:15:39 PM

Joined: Aug 2008
Posts: 308

All square numbers are positive.
Of course I was... testing.
 Logged
Post made November 15, 2008, 02:38:24 PM was deleted at the author's request.
RetroX
 Reply #8 Posted on: November 15, 2008, 09:57:23 PM

Master of all things Linux

Location: US
Joined: Apr 2008
Posts: 1055

As far as I know, C++ doesn't have an i constant.  Would be cool, though.
 Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars?
score_under
 Reply #9 Posted on: November 16, 2008, 06:47:57 AM

Joined: Aug 2008
Posts: 308

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:
Code: [Select]
`for(i=0;i<size;i++)`
 Logged
Josh @ Dreamland
 Reply #10 Posted on: November 16, 2008, 08:59:04 AM

Prince of all Goldfish

Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2956

XD @ i constant

Nah. C++ would just kill your game for you. ^_^
 Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
RetroX
 Reply #11 Posted on: November 17, 2008, 07:16:57 PM

Master of all things Linux

Location: US
Joined: Apr 2008
Posts: 1055

Not actually an "i" variable, but support for imaginary numbers.  You could always just do sqrt(-1). =P
 Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars?
 Reply #12 Posted on: November 22, 2008, 03:53:22 PM

Joined: May 2008
Posts: 1256

RetroX: #include <Complex>
 Logged
RetroX
 Reply #13 Posted on: November 23, 2008, 10:40:34 AM

Master of all things Linux

Location: US
Joined: Apr 2008
Posts: 1055

Wait, C++ has a library for that? O_O

EDIT: Holy shit.  That is awesome.
 Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars?
 Pages: 1