如何在给定该矩形中的坐标的矩形内识别子三角形

Pea*_*wer 1 vb.net geometry linear-equation

问题图解http://i49.tinypic.com/2iui4g.jpg

给定宽度为w且高度为h的矩形.和矩形中的坐标x,y我想确定我在哪个三角形内.

即函数应取参数(x,y)并返回a,b,c,d或表示该三角形索引的零基数,即(0 = A,1 = B,2 = C,3 = D)以该顺序.

我想这会是> =红线的公式和> =绿线的公式?

我想在VB.NET中实现它

Vla*_*lad 6

aboveRed = x*h > y*w;
aboveGreen = (w-x)*h > y*w;
if (aboveRed)
{
    if (aboveGreen) return "C"; else return "B";
}
else
{
    if (aboveGreen) return "D"; else return "A";
}
Run Code Online (Sandbox Code Playgroud)