Sign in to follow this  
f_shaukat

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

Recommended Posts

f_shaukat    122
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 this post


Link to post
Share on other sites
Promethium    580
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 this post


Link to post
Share on other sites
f_shaukat    122
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?

thanks in advance,
faisal

Share this post


Link to post
Share on other sites
Decrius    100
Quote:
Original post by f_shaukat
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?

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 this post


Link to post
Share on other sites
f_shaukat    122
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 this post


Link to post
Share on other sites
Decrius    100
Quote:
Original post by f_shaukat
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


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.

PS: did you read my post? Or didn't I add enough comments?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this