46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import math
|
|
|
|
def rectangular_layout(num_elements, max_dimension):
|
|
grid_size = int(math.sqrt(num_elements))
|
|
spacing = max_dimension // grid_size
|
|
return [
|
|
{
|
|
'position_x': (i % grid_size) * spacing,
|
|
'position_z': (i // grid_size) * spacing
|
|
}
|
|
for i in range(num_elements)
|
|
]
|
|
|
|
def circular_layout(num_elements, radius):
|
|
return [
|
|
{
|
|
'position_x': radius * math.cos(2 * math.pi * i / num_elements),
|
|
'position_z': radius * math.sin(2 * math.pi * i / num_elements)
|
|
}
|
|
for i in range(num_elements)
|
|
]
|
|
|
|
def diagonal_layout(num_elements, max_position):
|
|
return [
|
|
{
|
|
'position_x': i * max_position // num_elements,
|
|
'position_z': i * max_position // num_elements
|
|
}
|
|
for i in range(num_elements)
|
|
]
|
|
|
|
def triangular_layout(num_elements):
|
|
positions = []
|
|
row_length = 1
|
|
while num_elements > 0:
|
|
for i in range(row_length):
|
|
if num_elements <= 0:
|
|
break
|
|
positions.append({
|
|
'position_x': i * 10 - (row_length - 1) * 5, # Spread out each row symmetrically
|
|
'position_z': row_length * 10
|
|
})
|
|
num_elements -= 1
|
|
row_length += 1
|
|
return positions
|