1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
Function GetQuadValue:Float[](P:TPoint,A:TPoint,B:TPoint,C:TPoint,D:TPoint)
' longueur de chaque bord du quad
Local AB:Float = distance(A,B)
Local BC:Float = distance(B,C)
Local CD:Float = distance(C,D)
Local DA:Float = distance(D,A)
' aires de triangles formés par les bords et le point à tester
Local aAB:Float = aire(A,B,P)
Local aBC:Float = aire(B,C,P)
Local aCD:Float = aire(C,D,P)
Local aDA:Float = aire(D,A,P)
' influences des bords sur le point P
Local ratioAB:Float = 1 - (aAB / (aAB + aCD))
Local ratioBC:Float = 1 - (aBC / (aBC + aDA))
Local ratioCD:Float = 1 - (aCD / (aAB + aCD))
Local ratioDA:Float = 1 - (aDA / (aBC + aDA))
' projection du point sur chaque bord
Local P1:TPoint = New TPoint
P1.x = A.x * ratioAB + D.x * ratioCD
P1.y = A.y * ratioAB + D.y * ratioCD
Local P2:TPoint = New TPoint
P2.x = B.x * ratioAB + C.x * ratioCD
P2.y = B.y * ratioAB + C.y * ratioCD
Local P3:TPoint = New TPoint
P3.x = A.x * ratioDA + B.x * ratioBC
P3.y = A.y * ratioDA + B.y * ratioBC
Local P4:TPoint = New TPoint
P4.x = D.x * ratioDA + C.x * ratioBC
P4.y = D.y * ratioDA + C.y * ratioBC
' distances entre le point testé et les points projetés sur les bords
Local P1P:Float = distance(P1,P)
Local P2P:Float = distance(P2,P)
Local P3P:Float = distance(P3,P)
Local P4P:Float = distance(P4,P)
Local influence:Float[5]
' calcul final de l'influence de chaque coin
Local r1:Float = 1-(distance(P1,A) / DA)
Local r2:Float = 1-(distance(P3,A) / AB)
influence[1]=((r1 * (1-(P1P / (P1P+P2P))) + r2 * (1-(P3P / (P3P+P4P))))/2.0)
r1 = 1-(distance(P2,B) / BC)
r2 = 1-(distance(P3,B) / AB)
influence[2]=((r1 * (1-(P2P / (P1P+P2P))) + r2 * (1-(P3P / (P3P+P4P))))/2.0)
r1 = 1-(distance(P2,C) / BC)
r2 = 1-(distance(P4,C) / CD)
influence[3]=((r1 * (1-(P2P / (P1P+P2P))) + r2 * (1-(P4P / (P3P+P4P))))/2.0)
r1 = 1-(distance(P1,D) / DA)
r2 = 1-(distance(P4,D) / CD)
influence[4]=((r1 * (1-(P1P / (P1P+P2P))) + r2 * (1-(P4P / (P3P+P4P))))/2.0)
'la fonction retourne la tableau d'influence pour chaque point du quadrangle
Return influence
EndFunction |
Partager