Recent topics Log in
Search Profile
Memberlist Usergroups
Log in to check your private messages
Register
TTC with decimal number input
Post new topic   Reply to topic
SpaceTrace Forum Forum Index » Suggestions » TTC with decimal number input
View previous topic :: View next topic  
Author Message
DavAlan
Admiral
Admiral


Joined: 24 Aug 2004
Posts: 778
Location: Palo Alto, California

 Post Posted: Sat Jul 23, 2005 5:58 am    Post subject: TTC with decimal number input
Reply with quote

I came up with a need for a TTC (Travel Time Calculator) that takes decimal numbers as input for "mid point calculations" while in warp and decided do a quick 5 minute code job using C++ ....would be a nice feature to add to spacetrace. The code and output is very basic but...here it is....anyone with a C++ compiler can compile this into an exe file and hack away at it. Anyone without a compiler can msg me ingame for a working exe....

The distance calculation function will also determine the closest point on a line segment to a given point off the line. I will be modifying this code to allow for setting course vectors soon.

#include <iostream.h>
#include <conio.h>
#include <math.h>

#define MAX(a,b) ( (a)>(b) ? (a) : (b) )
#define MIN(a,b) ( (a)>(b) ? (b) : (a) )

int main()
{
float line_seg_point_dist_3d ( float x1, float y1, float z1, float x2,
float y2, float z2, float x, float y, float z );
float x1, y1, z1, x2,y2, z2, d;
float midx, midy, midz, t;
int s,m,h,w;
clrscr();
cout << "x1:" << endl;
cin >> x1;
cout << "y1:" << endl;
cin >> y1;
cout << "z1:" << endl;
cin >> z1;
cout << "x2:" << endl;
cin >> x2;
cout << "y2:" << endl;
cin >> y2;
cout << "z2:" << endl;
cin >> z2;
cout << "wf:" << endl;
cin >> w;
d = line_seg_point_dist_3d (x1, y1, z1, x1, y1, z1, x2, y2, z2);
midx = fabs((x2-x1) / 2) + fabs(x1);
midy = fabs((y2-y1) / 2) + fabs(y1);
midz = fabs((z2-z1) / 2) + fabs(z1);
cout << "DISTANCE = " << d << endl;
s = d * 3600 * 2.5;
s /= w;
h = s / 3600;
s = s % 3600;
m = s / 60;
s = s % 60;
cout << "ETA: " << h << " HOURS / " << m << " MINUTES / " << s << " SECONDS " << endl;
cout << "IN THE MIDDLE OF THESE COORDINATES: " << midx << "/" << midy << "/" << midz << endl;
getch();
return 0;
}

float line_seg_point_dist_3d ( float x1, float y1, float z1, float x2,
float y2, float z2, float x, float y, float z )
{
float bot;
float dist;
float t;
float xn;
float yn;
float zn;
if ( x1 == x2 && y1 == y2 && z1 == z2 ) {
xn = x1;
yn = y1;
zn = z1;
}
else {

bot =
( x1 - x2 ) * ( x1 - x2 )
+ ( y1 - y2 ) * ( y1 - y2 )
+ ( z1 - z2 ) * ( z1 - z2 );

t = (
( x1 - x ) * ( x1 - x2 )
+ ( y1 - y ) * ( y1 - y2 )
+ ( z1 - z ) * ( z1 - z2 ) ) / bot;

t = MAX ( t, 0.0 );
t = MIN ( t, 1.0 );

xn = x1 + t * ( x2 - x1 );
yn = y1 + t * ( y2 - y1 );
zn = z1 + t * ( z2 - z1 );

}

dist = sqrt (
( xn - x ) * ( xn - x )
+ ( yn - y ) * ( yn - y )
+ ( zn - z ) * ( zn - z ) );

return dist;
}
 Back to top »
View user's profile Send private message Send e-mail
Rubens
Admiral
Admiral


Joined: 20 Apr 2003
Posts: 1422

 Post Posted: Sat Jul 23, 2005 6:47 am    Post subject: l
Reply with quote

Ii thought that the title was clear enough....nice to see some programator helping out.
 Back to top »
View user's profile Send private message Send e-mail
promethius2
Admiral
Admiral


Joined: 02 Jun 2004
Posts: 1842
Location: Éire

 Post Posted: Sat Jul 23, 2005 1:30 pm    Post subject:

Indeed, it is nice to see a programmer in the game helping out.
What puzzles me, is what you would need this for.
Nevertheless, I'm sure many players will think it will come in handy so thanks DavAlan for helping out the game.
_________________
Calvin: I'm a genius, but I'm a misunderstood genius.
Hobbes: What's misunderstood about you?
Calvin: Nobody thinks I'm a genius.
 Back to top »
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
SpaceTrace Forum Forum Index » Suggestions » TTC with decimal number input
Post new topic   Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Solaris phpBB theme/template by Jakob Persson
Copyright © Jakob Persson 2003



Powered by phpBB © 2001, 2002 phpBB Group

Impressum