# coordinate double -> pixel int

• October 12th, 2013, 05:31 AM
Tchoumo
coordinate double -> pixel int
Hello,

I want to draw a Line with gDrawLine ().

What I would like to make, it is from coordinates such as A (0,2) and B (6,9), to ask gDrawLine to draw me this right with these coordinates. However, gDrawLine use a system of pixel to represent it.

As a result, for what I try to make, it is to create a function xToPixel, yToPixel so that the right coordinates A and B displays well in my window.

In a way, that my Line is proportional in my JFrame

Tracks? Thanks you
• October 12th, 2013, 05:45 AM
GregBrannon
Re: coordinate double -> pixel int
You're talking about Graphics.drawLine(), right? And you have a coordinate system in the JFrame that differs from that provided natively? Then I suggest you provide a translation from your coordinate system to the native coordinates and draw your lines using your values translated to JFrame's native coordinates.

I also recommend that you not draw directly on the JFrame but on a JPanel or other JComponent placed in the JFrame so that you can override the paintComponent() method.
• October 12th, 2013, 05:50 AM
Tchoumo
Re: coordinate double -> pixel int

Yes, i want to do a translation coordinate/pixel.
I already display them in a JComponent.

But the probleme is that I don't know how to do this conversion ..

I tried to do a translation of my real coordinate to pixel coordinate I'm searching a function to calcul it using xMin , xMax, the width of my JComponent etc
• October 12th, 2013, 05:59 AM
GregBrannon
Re: coordinate double -> pixel int
Describe your coordinate system in terms of the native coordinate system. From there, it's relatively simple math. For example, if the display area is 400 x 400, and you desire the center of the area ( 200, 200 ) to be ( 0, 0 ), that defines the translation. You might write down on paper the four corners and the center of the display area in both the native coordinates and your own to see how to translate across the entire displayed area.
• October 12th, 2013, 12:10 PM
Tchoumo
Re: coordinate double -> pixel int
I tried to search/try how to draw two line X absyssa /Y ordonate in (0,0) on the center of my JFrame and no success..

I also saw the translate method but the axe of Y is like top -> bottom and not bottom -> top like an basically graph
• October 12th, 2013, 12:43 PM
GregBrannon
Re: coordinate double -> pixel int
I don't get the difficulty. The center of your JFrame is:

centerX = frame.getWidth() / 2;
centerY = frame.getHeight() / 2;

That defines the center of the JFrame which is the origin of a coordinate system centered on the JFrame. I don't know what you're doing to make it so complicated. It's not.
• October 12th, 2013, 03:34 PM
Tchoumo
Re: coordinate double -> pixel int
Edited
• October 12th, 2013, 04:15 PM
GregBrannon
Re: coordinate double -> pixel int
That clears it up!

I have no idea what we're supposed to do with that - either one.