绘图仪中沿轴的合适标记距离

发布于 2024-08-14 07:43:12 字数 681 浏览 2 评论 0原文

我正在编写一个 2D 绘图仪,沿着 X 轴和 Y 轴我有带有打印值的标记。现在我的问题是:如何找到合适的距离?

到目前为止,我的方法(对于数字轴)是:

  • 我知道屏幕上轴的高度(以像素
  • 为单位)确定标记之间的最佳距离(以像素为单位)(在屏幕上看起来不错......),例如 32 像素。
  • 将像素数重新计算为轴值(例如,如果轴为 320 个像素,轴的范围为 0-40 °C,则值为 32 * (40/320) = 4。因此最佳距离为 4 °C .)
  • 从 1 °C 的距离开始。如果距离大于最佳距离,则将其除以二,直到小于最佳距离。同样,如果距离小于最佳距离,则将其乘以二,直到大于最佳距离。

这可行,但它并没有给我提供与我手动选择的距离相同的距离。例如:如果范围是 0-1000,我将决定以下距离之一:

  • 1000 (0, 1000
  • 500 (0, 500, 1000)
  • 250 (0, 250, 500, 750, 1000)
  • 200 (0, 200 , 400, 600, 800, 1000)
  • 100 (0, 100, ..., 900, 1000)
  • 50 (0, 50, ..., 950, 1000)

等等......

你有什么聪明的主意吗?

I'm writing a 2D plotter, and along the X- and Y-axis I have markers with printed values. Now my question is: how do I find suitable distances?

My method (for a numeric axis) is so far:

  • I know the height of the axis on screen in pixels
  • Decide an optimal distance between markers in pixels (what looks good on screen ...), for example 32 pixels.
  • Recalculate the pixel count to axis value (If the axis is 320 pixels and the range of the axis is 0-40 °C for example, the value is 32 * (40/320) = 4. So the optimal distance is 4 °C.)
  • Start with a distance of 1 °C. If the distance is bigger than the optimal distance, divide it by two until less then the optimal distance. And likewise, if the distance is less than the optimal distance, multiply it by two until larger than the optimal distance.

This works, but it does not give me the same distances as I would have selected by hand. For example: if the range is 0-1000, I would decide one of the following distances:

  • 1000 (0, 1000
  • 500 (0, 500, 1000)
  • 250 (0, 250, 500, 750, 1000)
  • 200 (0, 200, 400, 600, 800, 1000)
  • 100 (0, 100, ..., 900, 1000)
  • 50 (0, 50, ..., 950, 1000)

and so on ...

Do you have any clever idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天的雪花 2024-08-21 07:43:12

一个可能有帮助的建议是预先确定看起来不错的距离,然后根据轴上的范围大小定义一个查找表。但是,为了避免拥有太多数据,请确保您的轴标准化回标准范围。

例如,计算范围,然后标准化回 1-100 的范围,然后在查找表中找到最接近的值并使用该距离。

如果您有 Excel,您可以查看它们创建的结果,看看是否可以从中收集有用的算法,尽管我经常发现为了清晰起见,我需要手动覆盖 Excel 给出的距离。事实证明,手动覆盖对于您的应用程序来说也是一个重要的功能。

One suggestion that might help is to predetermine what distances will look good, then define a lookup table based on size of range on your axes. But, to save having to have too much data, make sure that your axes are normalised back to a standard range.

So, for example, calculate the range, then normalise back to a range of 1-100, then find the nearest value in your lookup table and use that distance.

If you have Excel you could look at the results they create and see if you can glean a useful algorithm from that, although I often find that I need to manually override the distances that Excel throws up for clarity. It might turn out that having manual override is a vital feature for your application too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文