Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by smjackal · Aug 03, 2012 at 04:50 PM · coordinate-systemcoordinate

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ScroodgeM · Aug 05, 2012 at 06:03 PM 1
Share

'pt' is a typographical measure unit, that is 1/72 inch. but pt != pixel AFAI$$anonymous$$...

avatar image Bunny83 · Aug 05, 2012 at 10:47 PM 0
Share

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.

avatar image smjackal · Aug 06, 2012 at 10:54 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges