2012-08-16 33 views
0

我想找到總數。如果我們給出了2D笛卡爾平面中所有三個頂點的x和y座標,則它們位於三角形邊界內和邊界上的點 。我在考慮將三角形包圍在一個矩形內,然後找到直線方程,並逐一檢查點以滿足不等式方程。有沒有更好的計算方法來解決這個問題?我們如何找到三角形內的點數?

請幫幫我。

+0

詳細闡述你的數學。你如何看待更多的數學能夠解決這個問題? – Makoto 2012-08-16 05:29:03

回答

1

您將3-triange邊緣向量的所有組合的交叉乘積。如果結果矢量的方向與矢量與點p的交叉乘積與三角形點(A,B或C)之一的交叉乘積的結果不相同,則p不在三角形中(交叉乘積將是導致3D)

更詳細的解釋: http://www.blackpawn.com/texts/pointinpoly/default.html

0

退房在http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry3PointInPolygon描述用於測試的一般情況的一個很好的總結點是否在多邊形。既然你有一個三角形,它總是凸的,這簡化爲(僞代碼):

for point in test_points: 
    //infinity can just be a point outside the bounding box of the triangle 
    ray := line from point to infinity 
    intersection_points := 0 

    for side in triangle_sides 
    isect := intersection ray, side 
    intersection_points++ if isect 

    return intersection_points %2 == 1