Get position of edge of rotated plane

Hi

So I have a plane and I want to get the positions of the edges of a plane within a job.

With this code I can get one of the edges:

                var minX = translation.Value.x - ltw.Value.c0.x * 10;
                var minZ = translation.Value.z - ltw.Value.c2.z * 10;

Now this works when the plane is not rotated. But how do I get the rotated position:

I have tried rotating the minX/minZ values from earlier around the center of the plane. But when I do this using this code:

            float s = math.sin(angle);
            float c = math.cos(angle);
            var rotatedX = c * (startPoint.x - pivot.x) - s * (startPoint.z - pivot.z) + pivot.x;
            var rotatedZ = s * (startPoint.x - pivot.x) - c * (startPoint.z - pivot.z) + pivot.z;
            return new float3(rotatedX,startPoint.y, rotatedZ);

The rotation follows an ellipsis instead a circle around the pivot point(center plane).

What am I doing wrong? Is there an easier way to get the positions of these edges?

var localLeftBottomCornerOfRect = new float3(-width/2f, 0, -height/2f);
var worldLeftBottomCornerOfRect = math.mul(ltw, new float4(leftBottomCorner, 1)).xyz;

Man, thanks for answering me! Really appreciate that.

For some reason it does not quite work yet. I believe I have to take scale into account somehow. Can’t figure out how.
Here’s my code:

                var width = compositeScale.Value.c0.x * 10;
                var height = compositeScale.Value.c2.z * 10;
                var localLeftBottomCornerOfRect = new float3(-width/2f, translation.Value.y, -height/2f);
                var worldLeftBottomCornerOfRect = math.mul(ltw.Value, new float4(localLeftBottomCornerOfRect.x,localLeftBottomCornerOfRect.y, localLeftBottomCornerOfRect.z, 1));

                var pos = new float3(worldLeftBottomCornerOfRect.x / compositeScale.Value.c0.x,
                    translation.Value.y, worldLeftBottomCornerOfRect.z / compositeScale.Value.c2.z);

                var instance2 = commandBuffer.Instantiate(entityInQueryIndex, test.Green);
                commandBuffer.SetComponent(entityInQueryIndex, instance2, new Translation
                {
                    Value = pos
                });

And the result:

So it works when the plane is at (0,0,0) but when the plane is moved or rotated it’s not right anymore.

If your rect is some scaled box\quad then you just should use 0.5 for width\height. You shouldn’t manually count scale, as it’s already in LocalToWorld matrix. In the video below look at scaled cube positioned not in (0,0,0).

using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;

public class DrawLineOfCornerInWorldSpace : SystemBase
{
    protected override void OnUpdate()
    {
        var deltaTime     = Time.DeltaTime;
        var rotationSpeed = 15f;

        Entities.ForEach((Entity e, ref Rotation rotationData) =>
        {
            rotationData.Value = math.mul(rotationData.Value, quaternion.RotateY(math.radians(deltaTime * rotationSpeed)));
        }).Schedule();
       
        Entities.ForEach((Entity e, in LocalToWorld localToWorldData) =>
        {
            var leftBottomLocal = new float3(-0.5f, 0, -0.5f);
            var leftBottomWorld = math.mul(localToWorldData.Value, new float4(leftBottomLocal, 1)).xyz;
           
            Debug.DrawRay(leftBottomWorld, new Vector3(0,5f,0), Color.red);
        }).Schedule();
    }
}

Awesome, thanks again!

For some reason in my environment I had to change the local to 5 instead of 0.5 with this change it works wonderfully.