如何在给定矩形中的坐标的情况下识别矩形内的子三角形
给定一个宽度为 w 、高度为 h 的矩形。和该矩形中的坐标 x,y 我想确定我在哪个三角形内。
即该函数应采用参数(x,y)并返回a,b,c,d或代表该三角形索引的从零开始的数字,即(0 = A,1 = B,2 = C,3 = D)如果它们是按这个顺序。
我认为这会类似于 >= 红线的公式和 >= 绿线的公式?
我想在 VB.NET 中实现这个
Given a rectangle of width w and height h. and a coordinate x,y in that rectangle I would like to identify which triangle I am within.
i.e. the function should take parameters(x,y) and return a,b,c,d or a zero based number representing that triangle index i.e. (0=A,1=B,2=C,3=D) if they are in that order.
I think this would be something like >= the formula of the red line and >= the formula of the green line?
I'd like to implement this in VB.NET
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
绿线方程:
h * x + w * y = h * w
红线方程:
x * h - y * w = 0
Equation of green line:
h * x + w * y = h * w
Equation of red line:
x * h - y * w = 0
我会考虑从左上角和右上角到点的线的角度。如果在两种情况下都小于 45 度(根据边的基本方向进行调整),则该点位于 C 中。其他组合将覆盖其他三个三角形。
您实际上不需要计算反三角函数来执行此操作,因为线长度的比率为您提供了足够的信息(并且 sin(45)...或者更确切地说 sin(pi/4) 是一个固定值) 。
I would consider the angle of the line to the point from the top left and top right corners. If it is less than 45 degrees (adjusting for the base direction of the edge) in both cases then the point is in C. Other combinations will cover the other three triangles.
You don't actually need to calculate inverse trig functions to do this, as the ratio of the lengths of the lines gives you enough information (and sin(45)... or rather sin(pi/4) is a fixed value).