- Home /
Convert arbitrary coordinates to texture pixel coordinates
I have data which describes word positions on a page in pt coordinates where 1 pt is 1/72 inch. I need to be able to transform these coordinates into pixel space relative to a texture pixel resolution of 1024 by 1587.
I know that I need to somehow normalise the pt coordinates and then use the resultant ratio to multiply by the texture width / height, but I'm not sure of the calculation to perform the normalisation. I'd be grateful for any suggestions.
Answer by ScroodgeM · Aug 05, 2012 at 01:21 PM
you need inches-to-pixels scale also known as DPI. without that your task has no solution.
Answer by Bunny83 · Aug 05, 2012 at 05:35 PM
The resolution of your texture is irrelevant when you have a certain DPI. You have a dpi (dots per inch) of 72, so just multiply your inch-value by 72, drop the fractional part and you have pixel coordinates:
var DPI = 72.0f;
var coords = new Vector2(2.12f, 3.15f);
coords *= DPI;
coords.x = Mathf.Floor(coords.x);
coords.y = Mathf.Floor(coords.y);
Debug.Log(coords);
This will print 152 / 226 which is the pixel coordinate of the given inch-coordinate (2.12 / 3.15)
'pt' is a typographical measure unit, that is 1/72 inch. but pt != pixel AFAI$$anonymous$$...
Yes, maybe i got the question wrong. By rereading it looks like he's talking about coordinates in pt (or point), but as you said, without the ratio between the realworld units (pt, inch) and the logical pixel unit it's not possible. It's all a matter of scale.
Thanks for your answers and I had come to a similar conclusions myself - there is no direct relationship between pts and pixels. So I need to know the ratio of the original coordinate system extents (width / height) and the target image extents . I can then use this ratio to calculate pixels coordinates to point coordinates or vice versa. Since the two coordinate systems in the case are proportional - this should not be a problem.
Your answer
Follow this Question
Related Questions
Can I transform all of my objects by referencing 2 points? 0 Answers
How to find coordinate 1 Answer
Putting object at the edge of the screen irrespective of resolution 2 Answers
How do I rotate around z-axis as if I am rotating around x-axis? 2 Answers
How do I use raycasts to see coordinates of the hit? 2 Answers