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 vishnu gb · Nov 22, 2014 at 05:25 AM · positiongridcheckinsideprogrammatically

Programatically check whether a grid is placed inside or outside a closed figure

Hi everyone, I want to build an application with the functionality

1-Draw a closed figure eg:alt text

2-Place a grid inside or outside eg:alt text

where a-Grid inside the closed figure and b-Grid outside the closed figure

3-programatically check whether the grid a is inside or outside the closed figure

u2.jpg (37.9 kB)
u1.jpg (29.0 kB)
Comment
Add comment · Show 4
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 koray1396 · Nov 22, 2014 at 07:52 AM 0
Share

you may want check out PolygonCollider2D and OverlapPoint.

avatar image robertbu · Nov 22, 2014 at 08:36 AM 0
Share

They common solution for checking if a point is inside or outside a closed figure is to walk each segment of the polyline that encloses the figure. For each segment, check to see what side (left or right) of the line formed by the segment the point is on. If the point is on the same side for all segments, then it is inside the polygon. For a rectangle, you'd have to check all four points and there are some degenerate cases with figure like #6 where all four points could be considered inside but part of the figure would be outside.

avatar image NoseKills · Nov 22, 2014 at 09:00 AM 0
Share

Like @robertbu points out, case 6 is the hard one here. You can do something like this to check if a point (corners of the rectangle) is inside a convex shape like 6, but even that doesn't work if one of the convex corners of shape 6 would go in to the checked rectangle through its side and out the same side: all corners would be inside but a side breaks the shape.

avatar image tanoshimi · Nov 22, 2014 at 09:36 AM 0
Share

Raycasting or winding algorithms should still work with concave polygons, but you'll need to test all four corners of the rectangle from all segments that define the containing polyline, which might be slow depending on how complex the shapes are.

You might also be able to take some shortcuts by defining $$anonymous$$imum bounding rectangles of each shape and doing an initial test against those - we'd need to know more about the potential bounds of the grid and shape though.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Compare Position of two gameobjects and if true, do nothing, help me please! 1 Answer

Minecraft style grid and block placement? 2 Answers

Help, can't get Grid to instantiate in the center of the screen 0 Answers

transform.position error 1 Answer

How to make a Vector3 A = Vector3 B EXACTLY 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