Calculating where vertices would be without rotation

I have a rotated object (a box collider in that case) and I want to calculate where its vertices would be, if it weren’t rotated.

My failed attempts for converting bounds.min:

The object is rotated 20 degrees in x and y and the non-rotated bounds.min is (1.0, 1.0, 1.0).

Collider collider = transform.GetComponent<Collider>();

Vector3 center = collider.bounds.center;
Vector3 min = collider.bounds.min;

Quaternion rotation;
Vector3 unrotatedMin;

// Using Quaternion.Inverse()
rotation = Quaternion.Inverse(transform.rotation);
unrotatedMin = rotation * (min - center) + center;
Debug.Log(unrotatedMin); // (1.2, 0.1, 0.6) != (1.0, 1.0, 1.0)
Debug.Log(rotation); // (-0.2, -0.2, 0.0, 1.0)
Debug.Log(rotation.eulerAngles); // (341.3, 338.8, 7.1)

// By hand
rotation = new Quaternion();
rotation.eulerAngles = new Vector3(-20.0f, -20.0f, 0.0f);
unrotatedMin = rotation * (min - center) + center;
Debug.Log(unrotatedMin); // (1.1, 0.3, 0.6) != (1.0, 1.0, 1.0)
Debug.Log(rotation); // (-0.2, -0.2, 0.0, 1.0)
Debug.Log(rotation.eulerAngles); // (340.0, 340.0, 0.0)

The same method for rotating vertices works later on in the code, when I rotate from zero rotation back to 20 degrees rotation. I’ve been trying all day, but I just can’t figure it out.

Use transform.localToWorldMatrix. To ignore the scale part of the matrix, use Matrix4x4.MultiplyVector. Bounds are really just that bounds. A cube that contains every vertex of the object. Bounds are never rotated (view left side of picture). You want calc the collider verts. I did something similiar for 2D, but you can easily convert it to 3D. Just assume a box, not rotated and with a scale of 1. Then rotate, scale, translate every vert of that box to your target box local space. (Dont forget to include the collider offset and scale)

  private void LoadColliderVerts(Collider2D collider, List<Vector2> verts)
        {
            verts.Clear();
            Type cTyp = collider.GetType();

            if (cTyp == typeof(BoxCollider2D))
                GetBoxColliderVerts((BoxCollider2D)collider, verts);
            else if (cTyp == typeof(CircleCollider2D))
                GetCircleColliderVerts((CircleCollider2D)collider, verts, _circleVertCount);
            else if (cTyp == typeof(EdgeCollider2D))
                verts.AddRange(((EdgeCollider2D)collider).points);
            else if (cTyp == typeof(PolygonCollider2D))
                verts.AddRange(((PolygonCollider2D)collider).points);
        }

        private static void GetBoxColliderVerts(BoxCollider2D collider, List<Vector2> verts)
        {
            Vector2 halfSize = collider.size / 2;
            verts.Add(collider.transform.TransformPoint(halfSize + collider.offset));
            verts.Add(collider.transform.TransformPoint(new Vector2(halfSize.x, -halfSize.y) + collider.offset));
            verts.Add(collider.transform.TransformPoint(-halfSize + collider.offset));
            verts.Add(collider.transform.TransformPoint(new Vector2(-halfSize.x, halfSize.y) + collider.offset));
        }

        private static void GetCircleColliderVerts(CircleCollider2D collider, List<Vector2> verts, int circleVertCount)
        {
            float anglePerCircleVert = (Mathf.PI * 2) / circleVertCount;
            for (int i = 0; i < circleVertCount; i++)
            {
                verts.Add(collider.transform.TransformPoint(new Vector2(collider.radius * Mathf.Sin(anglePerCircleVert * i), collider.radius * Mathf.Sin(anglePerCircleVert * i))));
            }
        }