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 /
  • Help Room /
avatar image
0
Question by ambid17 · Aug 22, 2017 at 01:23 AM · collisioncubevolumeintersectioncone

Cone and Cube intersection volume

So the project has a large cube made of up smaller, equal sized cubes. There will be 360 cones emanating from some center point in one degree increments, with separate conical sections (similar to the middle cone in the picture). I have to calculate the percent of volume that each cone section takes up in the cube. I've made it as far as adding colliders to each and registering the OnTriggerEvent. Now I am struggling to figure out the math to get this volume, as it needs to be precise as possible, preferably to the nearest tenth of a percent. I found a similar question but it might be overly complex since it's only cubes and cones in my situation: http://answers.unity3d.com/questions/1178637/finding-volume-of-two-3d-meshes-intersection.html alt text

screen-shot-2017-08-21-at-81916-pm.png (34.0 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 Bunny83 · Aug 22, 2017 at 01:54 AM 1
Share

There are still many things unclear about your situation:

  • a "Cone" and "Cube" are 3d volumes. What exactly do you mean by "one degree increments"? Do you arrange those "cones" in one "plane"? So the touching line between two neighboring cones lies in one plane?.

  • What's the size relation between the cones and the cube?

  • If it's a 3d problem, can the cube be rotated arbitrary in relation to the cone-ring?

  • Are you really interested in the actual physical intersection volume as a numeric value or just some sort of percentage. However if you want a percentage you have to define which is 100%. Obviously a ring of cones can never fill a cube shaped volume entirely.

A bit more background information would help to figure out the best way to approach your problem. Arbitrary intersecting a single cone with a cube can result in very nasty shapes when they partially intersect.

avatar image ambid17 · Aug 22, 2017 at 06:29 PM 0
Share

I'll answer your questions in order. 1. by one degree increments I mean that for each degree azimuth(the x-z plane in unity), there will be one cone. the cones are all angled with a specific elevation. The next elevation has the same amount of cones, just angled up a bit more. 2. The cones are a preset size, but the cubes can have their size changed (all of the cubes have to be the same size though) 3. the cubes will always be placed separate from the cones, they will always be facing the same way but the larger cube that the smaller ones parent from can be moved. 4. I really just need the percentage of the volume of the cube, taken up by intersecting section of a cone. At farther distances from the cone, the cone section could completely encompass the cube.

avatar image Bunny83 ambid17 · Aug 22, 2017 at 08:46 PM 0
Share

Does it have to be cones? There a many ways a cone can intersect even a single plane. Can't you just use a frustum / pyramid. It would still be quite tricky to calculate the intersection.

It highly depends on how exact you need the value. One approach is to simply systematically test points on a 3d grid inside the cube against the intersecting cones. This can be as precise as you want, but the complexity grows with O(x³). So a grid of 10x10x10 are 1000 test points while 20x20x20 are 8000 points and 40x40x40 are 64000 points.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 22, 2017 at 09:52 PM

Here's a helper struct that allows you to define a mathematical cone and test if a given point is inside the cone:

 public struct Cone
 {
     public Vector3 pos; // pos is the tip of the cone
     public Vector3 dir; // need to be normalized
     public float height;
     public float radius;
     public bool InInside(Vector3 aPoint)
     {
         Vector3 v = aPoint - pos;
         float d = dir.x*v.x + dir.y * v.y + dir.z * v.z;
         if (d < 0 || d > height)
             return false;
         Vector3 r = v - dir * d;
         d /= height;
         // if "pos" should be at the base of the cone you have to add this line:
         // d = 1f - d;
         return r.sqrMagnitude < radius * radius * d * d;
     }
 }

As said in the comments, "pos" defines the start point of the cone. It's usually at the tip of the cone. If i understood your situation correctly that's also how you defined your cones. "dir" is the normalized direction. It defines the orientation of the cone. "height" is the height of the cone along "dir" and "radius" is the radius of the cone at the base.

Now you can simply iterate through the volume of the cube and test as many points you like:

 float Intersect(Transform aCube, List<Cone> aCones, int aResolution)
 {
     var size = aCube.localScale;
     var f = aCube.forward * size.z;
     var r = aCube.right * size.x;
     var u = aCube.up * size.y;
     var s = aCube.position - (f + u + r) * 0.5f;
     float step = 1f / aResolution;
     int count = 0;
     for(int x = 0; x < aResolution; x++)
     {
         for (int y = 0; y < aResolution; y++)
         {
             for (int z = 0; z < aResolution; z++)
             {
                 for(int i = 0; i < aCones.Count; i++)
                 {
                     var p = s + (r * x + u * y + f * z) * step;
                     if (aCones[i].InInside(p))
                     {
                         count++;
                         break;
                     }
                 }
             }
         }
     }
     return count * step * step * step;
 }

This assumes a default Unity cube. So it's centered and has a size of 1 (half size of 0.5). The "aCones" list should only contain cones that actually intersect with the cube. Be careful what you pass in as aResolution value. A resolution of 100 will result in 1 million test points

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

105 People are following this question.

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

Related Questions

Detect Volume on Collision 1 Answer

2D IsOnGround check providing false positives 0 Answers

Vector2 intersection 0 Answers

Color Change on Collision Without Object Disappearing 0 Answers

Player intersecting with ground during jump landing 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