I made your pictures out of gizmos that update in real-time.

Just attach this script to an empty gameobject and hit play! Have fun moving the child and parent gameobjects around. Maybe the maths I used will help you out. **This only works for 2 Dimensions**!

```
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class MeshCreationHelper : MonoBehaviour
{
GameObject[] dots;
private void Start()
{
dots = new GameObject[4];
for (int i = 0; i < dots.Length; i++) {
dots *= GameObject.CreatePrimitive(PrimitiveType.Sphere);*
```

_ dots*.transform.SetParent(transform);*_*

_ }*_

** dots[0].transform.position = new Vector3(2.5f, 0, 4.5f);**

** dots[1].transform.position = new Vector3(5.5f, 0, 14.5f);**

** dots[2].transform.position = new Vector3(12.5f, 0, 10.5f);**

** dots[3].transform.position = new Vector3(6.5f, 0, 2.5f);**

** }**

** private void OnDrawGizmos()**

** {**

** if (EditorApplication.isPlaying) {**

** List points = new List();**

** // lines**

** for (int i = 0; i < dots.Length; i++) {**

*_ Vector3 A = dots*.transform.position;*

Vector3 B = dots[(i + 1) % dots.Length].transform.position;*_

** Gizmos.color = Color.cyan;**

** Gizmos.DrawLine(A, B);**

** var m = (B.z - A.z) / (B.x - A.x);**

*_ var b = A.z + (-m * A.x);_*

** // X aligned points**

** int startX = (A.x < B.x) ? Mathf.CeilToInt(A.x) : Mathf.CeilToInt(B.x);**

** int finishX = (A.x < B.x) ? Mathf.FloorToInt(B.x) : Mathf.FloorToInt(A.x);**

** for (int x = startX; x <= finishX; x++) {**

*_ float z = (m * x) + b;_*

** Gizmos.color = Color.red;**

** Gizmos.DrawSphere(new Vector3(x, 0, z), 0.1f);**

** points.Add(new Vector3(x, 0, z)); // add point for use with grid**

** }**

** // Z aligned points**

** int startZ = (A.z < B.z) ? Mathf.CeilToInt(A.z) : Mathf.CeilToInt(B.z);**

** int finishZ = (A.z < B.z) ? Mathf.FloorToInt(B.z) : Mathf.FloorToInt(A.z);**

** for (int z = startZ; z <= finishZ; z++) {**

** float x = (z - b) / m;**

** Gizmos.color = Color.red;**

** Gizmos.DrawSphere(new Vector3(x, 0, z), 0.1f);**

** }**

** }**

** // magic sort… sort vector3’s by x pos then y pos**

** List gridPoints = points.OrderBy(v => v.x).ThenBy(v => v.z).ToList();**

** for (int i = 0; i < gridPoints.Count; i += 2) {**

*_ var x = gridPoints*.x;*_*

*_ for (int z = Mathf.CeilToInt(gridPoints*.z); z <= Mathf.FloorToInt(gridPoints[i + 1].z); z++) {*_*

** Gizmos.color = Color.black;**

** Gizmos.DrawSphere(new Vector3(x, 0, z), 0.1f);**

** }**

** }**

** }**

** }**

*}*