# Complicated How to create objects that fill a specific area?

How to create objects that fill a specific area? How to instantiate cubes within a random 2D form ... Trying not to leave the black lines.

@ JaamiParvez

Objetive: • How do you currently represent the area you need to fill? Can you show us your code? Oct 20, 2019 at 19:22
• A list of coordinates. Oct 20, 2019 at 19:35
• Do you need to use squares to fill the space or would you be okay with filling the space with, let's say, triangles? Oct 20, 2019 at 19:48
• They could fill the shape with triangles too. - I use points into map to make the shape ... Point X, Y = (0.5, 0.5) Point X, Y = (0.0, 0.8) Point X, Y = (- 0.9, 1.2) Point X, Y = (- 1.0, 1.1) Point X, Y = (1.2, -1.0) Oct 20, 2019 at 19:51
• Then it should be quite easy to triangulate the shape, and then fill the generated triangles with a solid color or some texture. Oct 20, 2019 at 21:17

I'm not very familiar with C# so most of the code will be pseudo code. You probably have to adapt it to work for you. You wrote in a comment that you were okay with using triangles instead of squares, so the example below is generating triangles and edge shapes.

I also don't know anything about the coordinate system that you're using in your code, what engine you're using etc. In my code example below, the coordinate system has (0, 0) in the upper left corner of the window, with X+ pointing to the right and Y+ pointing down.

I can't help you with the rendering of the triangles and how the rigid bodies should be created, based on the triangles' information etc, since I, like I said, don't know what engine/library and physics library etc that you're using.

An example picture has also been attached below to show how the triangles are placed and how I've numbered the points of the triangles.

// Convenient way to store an X- and Y position in one combined unit
public struct Vector2D
{
public Vector2D(void)
{

}

public Vector2D(const float xPosition, const float yPosition)
: x(xPosition)
, y(yPosition)
{

}

public x;
public y;
};

// A simple 2D triangle struct containing 3 positions, one for each point in the triangle
public struct Triangle2D
{
public Triangle2D(void)
{

}

public Triangle2D(const Vector2D& rPoint1, const Vector2D& rPoint2, const Vector2D& rPoint3)
: point1(rPoint1)
, point2(rPoint2)
, point3(rPoint3)
{

}

public Vector2D point1 = new Vector2D(0.0f, 0.0f);
public Vector2D point2 = new Vector2D(0.0f, 0.0f);
public Vector2D point3 = new Vector2D(0.0f, 0.0f);
};

// The list containing the points that's forming the shape
List<Vector2D> pointList = new List<Vector2D>();

// Creating the collision triangles

// A list containing the generated triangles, based on the above shape's points
List<Triangle2D> triangleList = new List<Triangle2D>();

// The red triangle in the image below
triangleList.Add(new Triangle2D(pointList, pointList, pointList));

// The purple triangle
triangleList.Add(new Triangle2D(pointList, pointList, pointList));

// And the orange triangle
triangleList.Add(new Triangle2D(pointList, pointList, pointList));


And if you would like to generate edge shapes / collision lines instead:

// A simple 2D line struct containing 2 positions, one for each point in the line
public struct Line2D
{
public Line2D(void)
{

}

public Line2D(const Vector2D& rStart, const Vector2D& rEnd)
: start(rStart)
, end(rEnd)
{

}

public Vector2D start   = new Vector2D(0.0f, 0.0f);
public Vector2D end     = new Vector2D(0.0f, 0.0f);
};

// Creating edge shapes / collision lines

// A list containing the generated lines, based on the above shape's points
List<Line2D> lineList = new List<Line2D>();

// Line 1 - point 0 = start, point 1 = end

// Line 2 - point 1 = start, point 2 = end

// Line 3 - point 2 = start, point 3 = end 