Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 kevin0228ca · Jan 05, 2017 at 11:57 AM · objectsboundsoverlapvolumeintersection

Is there a functionality for finding how much two objects intersect each other

Hi, say I have two identical spheres, and want to know how much each intersect each other.

For example, when both at (0,0,0) it would be 100% intersect, and when one sphere is moved, maybe only 80% of the volume is intersected.

I looked at methods such as Bounds.Intersects and Physics.OverlapSphere, but those seems to only say if there is intersection, but not by how much.

Is there an functionality for what I am describing? A similar question is here, but wondering if there is simpler solution.

The scenario I am trying to use is to determine if a game object is moved to a specific place indicated by a silhouette.

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 Bunny83 · Jan 05, 2017 at 01:37 PM

Well, if you constraint your problem so you always have two identical spheres it's relatively easy.

Two identical spheres, as long as they intersect, have a single "cutting plane" which is located exactly halfway between the two spheres. Just imagine you cut both spheres at this plane. You will get 4 sphere pieces. Each sphere breaks up into a larger (`>50%`) and a smaller (`< 50%`) piece. You will ignore the larger ones and simply look at the smaller ones. The smaller pieces are Sphere caps so you can simply calculate the volume of each piece and add them together to get the whole intersection volume. Since the spheres are identical, both caps are also identical. So you can just calculate the volume of one cap and multiply it by 2. The result can be divided by the volume of a whole sphere to get a value between 0 and 1.

Let "a" and "b" be the position of sphere A and sphere B. "r" is the radius of both spheres

 float IntersectSphereVolume(Vector3 a, Vector3 b, float r)
 {
     Vector3 ab = b - a;
     float halfLength = ab.magnitude * 0.5f;
     if (halfLength > r)
         return 0; // no intersection
     float circleRadiusSqr = r * r - halfLength * halfLength;
     float height = (r - halfLength);
     float vCap = (3*circleRadiusSqr + height*height) * height * Mathf.PI / 6f;
     
     float vIntersect = vCap * 2f;
     float vSphere = r*r*r*Mathf.PI * 4f / 3f
     return vIntersect / vSphere;
 }

Just written from scratch so i can't confirm it works properly ^^. This method returns a value betwen 0 and 1 where 0 means no intersection and 1 when the two spheres are at the exact same position.

If you don't need the exact volume matching you could simply use a linear error like this:

 float IntersectSphereVolume(Vector3 a, Vector3 b, float r)
 {
     Vector3 ab = b - a;
     return Mathf.Clamp01(1f - ab.magnitude / (2*r));
 }

This will also return a value between 0 and 1 but the curve will be linear.

ps: In the first method one could cancel out Mathf.PI and some other factors as we finally just divide both volumes through each other, However i kept it so it's clear what happens. Also you can use the volume for other things.

If the spheres have different radii or aren't spheres at all this is getting much more complicated and doesn't have a general 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 Fressbrett · May 22, 2020 at 01:44 PM

This is an old question, but for concave meshes you need boolean operations, which is quite complex math - but luckly well understood.

If one of your meshes is concave and the other is convex, have a look at the Sutherland-Hodgman algorithm. However, this algorithm requeries one mesh to be convex. If you want both to be convace and also want to take care of edge cases, you need to go for boolean operations, such as the Martinez algorithm. The paper is called "A new algorithm for computing Boolean operations on polygons".

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

What's the best/easiest way to do something like Bounds.Intersects but accounting for rotation? 1 Answer

Mesh collider not working as expected 2 Answers

(2D intersection+picture)How to show up the invisible object when intersect with another object. 1 Answer

Object overlap marking 0 Answers

Calculate Bounds Intersection Face Normal 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