Anything better for a 2D rectangle in 3D space than Bounds?

I need to do some calculations based on a non-rendering rectangle that exists in 3D space. Using a Bounds would be okay, but I don’t need its third dimension, so I don’t really want to use extra resources for that. However, that’s what I’m going to do, for code clarity, unless you can recommend something better.

There is no built-in data structure for a 2D rectangle in 3D space. However, unless you’re using thousands of rectangles at once, the storage space for the extra float isn’t going cause any problems.

Is the rectangle axis-aligned or freely rotated in space?

Freely rotated.

In that case, Bounds isn’t what you want. You’ll notice that Bounds doesn’t have a rotation. It is always an axis-aligned box.

Are you doing a point-in-rect for a rect that can have any alignment? So it is effectively a rectangular prism and you want to see if points are anywhere inside it?

Not true! Check out this lil’ project for proof! :smile:

Now, Unity certainly doesn’t make it easy to create arbitrary rotated Bounds, but what I need to do is based around mesh.bounds anyway.

I don’t know what you’re talking about, so I doubt it! :o

What I’m mainly using this for is, I create a rectangle that represents the front of an object that sits in a doorway. Then I do some calculations based on one of four corners of that rectangle (the appropriate one is found via a cross product and quaternion calculation), and where the camera is. Using a dot product, I can then set the nearClipPlane of the camera to exactly how large it needs to be to be able to see the whole object in the doorway.

222620–8067–$fun_with_bounds_113.zip (462 KB)

I think you’ve almost settled on this yourself, but a good structure for an arbitrarily rotated rectangle/parallelogram is a point of origin (one corner) along with two vectors representing the lengths and directions of the sides. If you use the same convention as the cross product for the ordering of these two vectors, you can be consistent about which direction the rectangle is facing.