• 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 axxion · Nov 20, 2016 at 09:51 AM · nestedcolliding

how much area colliding

hi everyone

my question: i have 2 objects and this two shape starting collide, this 2 object not have rigidbody. i want calculate how much nested this two object, like attached image: alt text

screen-shot-2016-11-19-at-231140.png (17.8 kB)
Comment
Add comment · Show 3
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 TreyH · Nov 20, 2016 at 12:37 PM 0
Share

Are you only dealing with cubes? if so, that is a straightforward geometry exercise.

$$anonymous$$ore complicated meshes will make things a bit different. What are you trying to do with this information?

avatar image Bunny83 · Nov 20, 2016 at 01:05 PM 0
Share

Like TreyH said it highly depends on your specifications:

  • Do you always just need to check two objects?

  • Are they always cubes?

  • Do they always have the same size?

  • Are they always axis-aligned?

If you answer any of those questions with "no" it gets much more complex / complicated. If you can say "yes" to all it's fairly easy.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Nov 29, 2016 at 02:06 AM

Sorry for the late response ^^. I currently have about 150 UnityAnswers tabs open.

Well as i said having arbitrary meshes makes it way more complicated. Especially since the right "red" object is not convex. If you only deal with convex objects it's easier. So if you really need the general case there is one initial requirement: the meshes need to be closed otherwise the concept of "inside" and "outside" makes no sense. So if you have two arbitrary closed meshes you have to do;

  • split each mesh into one or multiple convex meshes. Every "closed" mesh can be broken down into convex meshes but it might not be that simple to do so. The result of the first step is that the initial Mesh A and Mesh B has been broken down into A1, A2, ... and B1, B2, ... where each one is a convex mesh.

  • In the second step you would convert each face of lets say all A meshes into mathematical planes that can be used to intersect the meshes with each other.

  • Now you have to cut down all B meshes by all planes of each A mesh. The resulting convex mesh is the intersection mesh between the two convex meshes. So when you intersect n x A meshes with m x B meshes you will end up with (n * m) x C meshes. However some of these meshes will be "empty" and can be discarded.

  • In the final step you have a collection of all intersection volumes as convex meshes. Now you just need to calculate the volume of those meshes. Since they are all convex you can simply split it logically into tetrahedron. From there it's easy to calculate the volume of each part. Finally just add up the volume of each part.

  • If you want a "percentage" in relation to one of the two initial meshes you would need to calculate the volume of that reference mesh as well. Since you already have the mesh as convex parts that's fairly easy.

If you have problems with the implementation, here's my VisPortal demo. You can use the Polygon class inside PolyArea.cs to represent a single "face" / triangle of your mesh. It has a clipping method to clip it against some clipping planes. The great thing about convex meshes is that when you intersect all border planes with each other you get the exact faces of the mesh.

As i said this is not going to be easy. This is actually the same what is needed for calculating CSG operations on meshes.

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I am having a problem with detecting certain collision? 1 Answer

differentiate between box collider of two different Game Objects in UNITY 1 Answer

Nested Selection Grid? 1 Answer

Instantiating a nested class ScriptableObject 0 Answers

How to access methods from nested static java classes 0 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