图形 - 考虑到一条线的宽度,我如何知道一条线在屏幕上是否可见
我正在做一些核心图形,我想知道如何知道一条线的某些部分是否在屏幕上可见。
让我们画一条从 x-5, y3 到 x2, y-7 的线。如果宽度为 1 像素,则屏幕上不会显示任何内容。如果宽度为 15 像素,则会显示其中的某些部分。
我该如何检查?
I'm doing some core graphics, and I wonder how I may know if a line will have some parts of it visible on screen.
Let's take a line going from x-5, y3 to x2, y-7. If it's 1 pixel wide, nothing will be displayed onscreen. If it's 15 pixels wide, some parts of it will be displayed.
How may I check that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只有线路,则可以使用以下功能。否则,我建议遍历线条的整个长度,并在特定距离内创建线条宽度尺寸的平方,并检查它是否在您的视图内。示例:如果有一条从 x0y0 到 x7y0 的线。您可以使用 x1y0 创建一个绘制线大小的正方形(在本例中为 15),然后查看它是否与您的屏幕重叠。接下来转到 x2y0 等等。优点是它甚至可以与贝塞尔曲线一起使用(一点维基信息如何贝塞尔曲线就足够了)。
// 编辑:(做了一个小贝塞尔曲线检查功能,应该可以工作,但还没有测试)我认为在绘制之前检查每条线的性能效率并不高:
// 编辑结束
但现在让我们看看简单的线功能:
您将获得4分。 2 条线,一根在原始线上方,一根在原始线下方,尺寸为绘制宽度的一半。后面的计算是获取绘制方向以及与原始线的差异。但对于那些想要了解它的人,这是我的预先计算:
If you have lines only you can work with the function below. Otherwise I would recommend to go through the whole length of your line and create in a specific distance an square of the line width size and check if it is inside your view. An example: If you have a line from x0y0 to x7y0. You would go to x1y0 create a square of your draw line size (in this example 15) and see if this overlaps your screen. Next go to x2y0 and so on. The advantage is it will even work with bezier curves (a little wiki information how bezier work will be enough).
// EDIT: (made a little bezier check function, should work, but haven't tested) And I don't think its more performance efficient to check each line before drawing:
// EDIT end
But now lets go to the simple line function:
you will get 4 points. 2 lines, one above and one below the original line, half the size of your draw width. The calculation behind is to get the draw direction and for that the difference to the original line. But for those who want to get into it, heres my pre calculation: