【问题标题】:Algorithm for getting position value between 0 and 1获取0到1之间位置值的算法
【发布时间】:2015-10-30 18:43:37
【问题描述】:

所以我正在制作某种 2d 物理引擎(是的,我知道从头开始制作物理引擎很难)并且我需要一些帮助。

我需要一个算法来说明在屏幕上绘制多边形顶点的位置,它应该给出一个介于 0 和 1 之间的数字,0 是可能的最小位置 (0),1 是可能的最大位置(窗口宽度或高度(1920 或 1080))。

我给每个多边形这些变量:

// = comment

x = [a number wetween 0 and 1]
y = [allso a number between 0 and 1]
width = [between 0 and 1]
height = [between 0 and 1]

vertices = [ // This makes a triangle
    0,   1, // bottom left of a "box" created at [x] * [window width], [y] * [window height] with the width of [width] * [window width] and height [height] * [window height]
    1,   1, // bottom right of the "box"
    0.5, 0 // top middle
]

我怎样才能在屏幕上的哪个位置(以 0-1 格式)绘制顶点?

【问题讨论】:

    标签: algorithm polygon vector-graphics


    【解决方案1】:

    哦,我现在明白了。我是[x or y] + ([width or height] * [vertice])]

    【讨论】:

      【解决方案2】:

      如果我正确理解您的问题,您想设置相对于框的边界的顶点并将它们转换为像素坐标。这可以按如下方式完成:

      translate(x) = (vertex_x * box_width + box_x_start) * pixel_width

      translate(y) = (vertex_y * box_height + box_y_start) * pixel_height

      【讨论】:

      • 不,我想知道各个顶点的绘制位置:/
      • 是的,所以如果x = 0.5,那么x像素坐标就是0.5 * 1920 = 960。与y 坐标相同。
      • 是的,这给了我多边形“框”的左上角在哪里,我想知道应该在哪里绘制多边形的各个点/顶点
      • 对不起,我误解了你的问题。我已经更新了我的答案。
      猜你喜欢
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      相关资源
      最近更新 更多