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
1
Question by Tsanas · Mar 02, 2012 at 12:29 PM · rectrectanglebottom

Rect.ymax wrong?

Hello.

I got a simple problem:

I start by creating a new rectangle in (0, 0) with a width and height of 100.

Now, according to this, the y-coordinate is the top of the rectangle.

So if the top is 0 and it's height is 100, the bottom coordinate should be (-100), right?

Well, not according to Rect.yMax, which says the coordinate is (100) (positive).

But according to this, the yMax property should return the bottom coordinate.

So is this a bug or am i misunderstanding something?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Kleptomaniac · Mar 02, 2012 at 02:47 PM

I'm not an expert on screen coordinates, but I believe in computing systems the screen origin (0,0) is always in the top-left corner of the screen. From that origin point, the coordinates at the very bottom of the screen and the very right of the screen are accounted for as being positive. This means that despite what you might think about normal coordinate geometry, as we go down the screen the y-coordinates become larger as opposed to becoming smaller as you assumed they should have.

Conversely, anything above what the maximum y coordinate of the screen is becomes negative and anything further to the left (x-axis) than the dimensions of the screen allow becomes negative. So, if your rectangle had coordinates of (-100, -100), it would be completely off the screen.

So, in fact, in this case (your rectangle being drawn at the origin point of the screen), the bottom coordinate should be positive 100 as Rect.yMax reveals.

I hope that made some element of sense ... if not, hopefully I'll be able to elaborate a bit better!

Klep

Comment
Add comment · Show 4 · 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 Tsanas · Mar 02, 2012 at 03:00 PM 0
Share

Doh!

I actually thought about that, but im not sure why my head refused to accept that. I think i've had a brain-fart.

Thanks for the answer!

avatar image Eric5h5 · Mar 02, 2012 at 03:08 PM 2
Share

The origin depends on what coordinate system you're using. GUI space has 0,0 at the top-left, screen space has 0,0 at the bottom-left.

avatar image Bunny83 · Mar 02, 2012 at 05:55 PM 1
Share

Exactly, but the Rect struct always act the same way. The rect actually stores m_X$$anonymous$$in, m_Y$$anonymous$$in, m_Width and m_Height. Nothing more. All other properties are calculated out of these values. x$$anonymous$$in and x just return m_X$$anonymous$$in. x$$anonymous$$ax return m_X$$anonymous$$in + m_Width.

The difference in x and x$$anonymous$$in is when you set them. x just sets directly m_X$$anonymous$$in so m_Width stay the same. If you set x$$anonymous$$in it will make sure that x$$anonymous$$ax will stay the same. Therefore m_Width is changed.

Because Rect is used in may different cases they deprecated left, right, top and bottom because it's misleading.

avatar image demented_hedgehog · Sep 20, 2015 at 12:14 AM 0
Share

I really don't think the unity documentation explains this well at all. That rect documentation with the y$$anonymous$$ax at the top is very misleading imho.

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

8 People are following this question.

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

Related Questions

Unity UI Rect 0 Answers

Problems with Rect 1 Answer

Is there a way to color in a rect? 1 Answer

Why can't GUI.Box have a width of 5 or less? 1 Answer

Bounds vs. Rectangle 1 Answer


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