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: Finding volume of two 3D meshes intersection. - Questions & Answers - Unity Discussions
100359-screen-shot-2017-08-21-at-81916-pm.png

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*.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