Math 根据项目数量和屏幕比率拆分屏幕

Math 根据项目数量和屏幕比率拆分屏幕,math,language-agnostic,grid,formula,equation,Math,Language Agnostic,Grid,Formula,Equation,我必须平均分割屏幕(尽可能)给定一个动态的项目数 因此,我需要根据屏幕大小/比率找到列数和行数 每个项目大小都不重要,因为我将根据每列和每行项目的百分比计算它们 如果我有5个项目,那么(取决于屏幕比例),我可能会在第一行有3列,在第二行有2列。没关系。首先,你必须决定“平均划分屏幕”是什么意思。 这可能意味着每个项目都有一个首选的x-y比 您可以使用下面的算法,该算法有利于接近所需的x-y比,而不是减少空空间的数量 // Set this to the desired x-to-y ratio.

我必须平均分割屏幕(尽可能)给定一个动态的项目数

因此,我需要根据屏幕大小/比率找到列数和行数

每个项目大小都不重要,因为我将根据每列和每行项目的百分比计算它们


如果我有5个项目,那么(取决于屏幕比例),我可能会在第一行有3列,在第二行有2列。没关系。

首先,你必须决定“平均划分屏幕”是什么意思。 这可能意味着每个项目都有一个首选的x-y比

您可以使用下面的算法,该算法有利于接近所需的x-y比,而不是减少空空间的数量

// Set this to the desired x-to-y ratio.
const preferred_ratio = 1.2; 

function calc_cols_rows(In: screen, In: num_items, Out: num_rows, Out: num_cols) {
  desired_aspect = (screen.width / screen.height) / preferred_ratio;

  // Calculate the number of rows that is closest to the desired aspect:
  num_rows = round(sqrt(num_items / desired_aspect));

  // Calculate the required number of columns:
  num_cols = ceil(num_items / num_rows);
}

问题到底是什么?如何调整正方形网格的大小以容纳N个项目?对于N=8,您喜欢正好适合8的长方形2x4网格,还是有空空间的方形3x3网格?