I am utilizing Unity’s Grid system, and I am drawing triangles on the grid. Every triangle is recorded as a Vector2Int
origin level and a Record
of three Vector2Int
s recording its relative vertices, as an illustration:
origin = new Vector2Int(0, 0);
relativeVertexPositions = new Record<Vector2Int>() {
new Vector2Int(-3, 0),
new Vector2Int(3, 0),
new Vector2Int(0, -3),
};
It is a bit bizarre that the origin is on the underside of the triangle nevertheless it’s for an in-game cause – a personality is supposed to face there. I can redefine the origin level to elsewhere within the triangle if wants be.
The above code would generate a triangle as follows:
I am utterly caught on the best way to discover out whether or not a given Vector2Int
(i.e. an integer x,y place – that is presumably an engine-agnostic downside) is absolutely contained in the triangle. These 4 squares are marked in blue on my sketch. Triangles differ in dimension, however all the time observe this similar logic – in a size-4 triangle, there shall be 9 inner x,y coordinates; in a size-5 triangle, there shall be 16, and so forth.