max size of a cube at irregular angles

Hello, please forgive my lack of terminology. I feel like this should be a simple thing, but I can’t find the words to find the proper answer.

How can I get the size of a cube at an irregular angle using bounds (collider) and a direction(vector3).

I have a bounding box, which can give me XYZ size, but I want the max size if the bounds are approached at a particular direction.

As per my crappy MS paint example. I have cube with bounding box, and a random direction, so how would I measure that artfully drawn purple line.

Thanks.

It’s not really clear what you want to know exactly. However the Bound is an AABB (Axis Aligned Bounding Box). So it’s always aligned with either the world space (in case of Collider.bounds or Renderer.bounds) or aligned with the local space of the object (in case of Mesh.bounds). To calculate an arbitrary bounding box you would need to iterate through all vertices of the object and transform them into your desired space / orientation and calculate the bounding box there manually.

It’s not clear on what information you want to base your calculations on. In your screen shot you’ve drawn your purple line in screen space of the editor camera. So you should try to be more precise about your usecase and what you need this for.

@Bunny83 Well I guess he want’s the actual Size in 3d Space. So the easiest way is to get the Renderers BB’s.(World Space)

to get the Actual Size simply do this:

``````Vector3 ActualSize = GetComponent<Renderer>().bounds.size;
``````