# how to draw a line of 2.3 mm width on a printer

This topic is 3709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, Please tell me how to draw a line of 2.3mm width on a printer? If i want to use the glLineWidth then i can specify the width in terms of number of pixels. But how can i find the exact number of pixels that are equal to 2.3mm??. Because the resolution of the printer is different in X and Y directions and i am not sure which resolution should i take to calculate the number of pixels that are equal to 2.3 mm?? Please help. I thank you in advance. Faisal.

##### Share on other sites
This is what DPI (dots per inch) is for. For instance a DPI of 70 means that there are 70 dots, or pixels, for every inch. So to draw a line that is X mm wide, convert it to inches, and use the DPI to find the width in pixels.

##### Share on other sites
But there are two Apis in windows. One for dots per inch in the horizontal direction and the second for the dots per inch in the vertical direction. And my question is that which one to use? horizontal or vertical?

faisal

##### Share on other sites
Quote:
 Original post by f_shaukatBut there are two Apis in windows. One for dots per inch in the horizontal direction and the second for the dots per inch in the vertical direction. And my question is that which one to use? horizontal or vertical?thanks in advance,faisal

Math ftw.

If you need a diagonal line which is 2.3 by 2.3 mm (so in length it is sqrt(2 * 2.3^2)), and horizontal DPI is 70, vertical is 80, this means it should vertically be stretched by 80/70 (= 1.1429).

2.3 mm = 0.090551181 inch

pixels = inches * DPI

In width: 0.090551181 * 70 = 6.3386 pixels
In height: 0.090551181 * 80 = 7.2441 pixels

7.2441
------ = 1.1429
6.3386

As I said, it would be vertically streched on screen this way.

Good luck.

##### Share on other sites
I could not understand this solution. Does this mean that i should call glLineWidth(1.1429)? And i also do not understand why you are computing it from the x-length and y-length of the line. Because we are discussing only the width of the line.

regards,
Faisal

##### Share on other sites
Quote:
 Original post by f_shaukatI could not understand this solution. Does this mean that i should call glLineWidth(1.1429)? And i also do not understand why you are computing it from the x-length and y-length of the line. Because we are discussing only the width of the line. regards,Faisal

Than I don't see why it would matter to you that the Y-axis has a different DPI then the X-axis.

x-length = width

1.1429 = the factor

So you need to do glLineWidth(6.3386) to get a line with width 2.3mm on paper.

• 38
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631362
• Total Posts
2999577
×