Click here to Skip to main content
15,886,786 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi,

What I need exactly :
- I would like to know how I can interpret the data (see below) for drawing a map in a window or picturebox or whatever and being able to drag the image into the control. I tried in C# and in C++ with opengl, at the end I had the same problem, I dont know how to convert/use the data for drawing points and line while conserving proportion.


Context :

I have a MySql database with a table "MapSolarSystems". Into this table, we can retrieve the name of the "solar-system" and his coordinate X,Y,Z (data type: Double).
Each system have a field "constellationID" which help us for grouping. Generally a "constellation" contain less than 10 "solar-systems"

Let me show an example of one row:

int constellationID = 20000001
varchar solarSystemName = FooBar
double    X = -8.85107925999806e+016 
double    Y =  4.23694439668789e+016 
double    Z =  4.45135253464797e+016 
double xMin = -8.85119031484906e+016 
double xMax = -8.85092564717606e+016 
double yMin =  4.23692979274891e+016 
double yMax =  4.23696457492639e+016 
double zMin =  4.45130363558928e+016
double zMax =  4.45141116897829e+016


The result expected after drawing a constellation in 2D look like that :
Illustration (picture)


Once I know how to deal with thoses data, I will use some algorithm like the "Delaunay Triangulation" and "Djikstra" (I got already some opengl samples).


Thanks for reading me, sorry for the grammar.
Posted
Comments
fjdiewornncalwe 17-Dec-10 10:37am    
You really need to make an attempt to do it yourself first and then ask more specific questions related to issues that arise in that process. We are not here to do your homework for you, we are here to help you when you get stuck. The effort you put in will reflect the effort members here make in answering your questions.
jo le serb 17-Dec-10 12:18pm    
thanks for answering anyway. Maybe is my english.

I am working on that somes month ago myself, making a ton of test-projects, sometime more than 6 hours per day. So now, I need help, I cant reach my goal myself. thanks.

I dont want an COMPLETE source-code or program. I only want to know how to convert/use the data for drawing points and line while conserving proportion.

I mean, if X,Y was equal to eg: X=200, Y=55 instead of the double-value, I could have done myself, without asking help.

Now, X=-8.85107925999806e+016 and Y = 4.23694439668789e+016: How I can convert or draw like using :


internal Point CoordToPixel(Double X, Double Y)
{
return new Point(Convert.ToInt32(X), Convert.ToInt32(Y));
}

graph.DrawLine(new Pen(Color.Black, 2), CoordToPixel(X, Y), CoordToPixel(X2, Y2));



edit: fail edit..
Richard MacCutchan 17-Dec-10 13:35pm    
You can scale your values first and convert the scaled values to integers, or you can use floats to draw points/lines. Take a look at the alternate drawing methods of the graphics class.

I think the issue is one of scaling. Check the limits of your drawing surface (Window, panel etc) and scale your largest coordinate such that it fits within that surface. Then apply the same scale factor to all other coordinates to complete your picture. If the picture is then out of proportion you may need to add a second scale factor which is the ratio between width and height. It's some while since I have done this myself so I'm working from (vague) memory here.
 
Share this answer
 
Comments
jo le serb 17-Dec-10 12:20pm    
Thanks, yes it is.

But my main problem is dealing with this type of data. If it was INT would be easy to work with.
JOAT-MON 17-Dec-10 17:19pm    
The numbers are just really big integers. They are expressed in exponential notation where:
e means exponent notation, + or - means the direction left or right of the decimal, and the number on the right is the number of zeros.
see: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx for information on numeric formats.
Richard MacCutchan 18-Dec-10 5:22am    
@JOAT-MON: No kidding Sherlock!
OK if I understand correctly your problem is converting the double values to pixel coordinates. If that is the case you need to do something like this:

C++
POINT CoordToPixel(Double X, Double Y)
{
    double XDistance = LargestXVal - SmallestXVal; //Largest distance on the X axis
    double YDistance = LargestYVal - SmallestYVal; //Largest distance on the Y axis
    double LargestDistance = (XDistance >= YDistance) ? XDistance : YDistance; //Choose the larger of the 2 distances
    double Scale =
        ((DisplayAreaXSize <= DisplayAreaYSize ?
        DisplayAreaXSize : DisplayAreaYSize) //Choose the smallest dimension so the whole thing fits in the display area.
        - BORDER_SIZE * 2) / LargestDistance; //BORDER_SIZE is the size of the border you want.
    
    POINT ScreenPosition;

    ScreenPosition.x = (X - GetSmallestXVal()) * Scale + BORDER_SIZE + 0.5;
    ScreenPosition.y = (Y - GetSmallestYVal()) * Scale + BORDER_SIZE + 0.5;

    return ScreenPosition;
}

You will need to figure out how to get the border size, display area's X & Y sizes and the largest and smallest X & Y values but none of those should be too much of a problem.

EDIT: Don't forget to add the border offset to the X and Y coordinates. Also I added + 0.5 to X and Y for rounding purposes.
 
Share this answer
 
v7
Comments
jo le serb 18-Dec-10 7:30am    
It worked sir.

http://img684.imageshack.us/img684/3604/captureiy.png
Mr Nukealizer 19-Dec-10 16:16pm    
Glad I could help.
Thanks you for your help all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900