Search code examples
javaembedded2dlinegraphics2d

What is the measure unit of Graphics2D or the 2D Components?


I'm working on a code that should allow me to draw an AC "Animated electricity" signal, and the time interval should be accurate in this case. My question is; What is the measuring unit of the Point2D specifically, Is't pixels, milliseconds, or any unit else? I'm trying to draw a Line2D, which should be drawn between two points! I'd tried to take the '1' value as milliseconds and it's kind of worked, later on I discovered that the graphics elements is measured by pixels, I tried to convert millisecond to pixels with multiplying by pixel value, but it didn't give me the expected results. My code as following expecting '1' value is Millie

<i>
for(i=0;i<20000;i++)
            {
                //System.out.println(volts[i]);

                if(i!=0)
                    g2d.draw(new Line2D.Double(time-(timeScale/y),-(((voltScale/x)*50*volts[i-1])-300),time,-(((voltScale/x)*50*volts[i])-300)));
                time+=(timeScale/y);
            }
</i>

Solution

  • The Graphics2D class description gives a fairly good description of the units (in the "Coordinate Spaces" section:

    https://docs.oracle.com/javase/8/docs/api/java/awt/Graphics2D.html

    Generally speaking, a unit in "User Space" (the Java2D coordinate system) will correspond to 1/72 inch on physical devices (such as your monitor or your printer).