Aujourd'hui nous sommes le 03/06/2025 02:33:14.
Routines GFA-Basic 32Nom : Angle | Description : Retourne l'angle en Radian d'un segment de droite x1,y1,x2,y2. Dans cette fonction les sinus sont en x. |
Listing : Function Angle(x1#, y1#, x2#, y2#) As Double Local Double lx, a, h lx = x2 - x1 h = Sqr(lx ^ 2 + (y2 - y1) ^ 2) If h > 0 lx = lx / h If y2 > y1 a = Asin(lx) Else a = PI - Asin(lx) EndIf EndIf If a < 0 a = a + 2 * PI EndIf Return a EndFunc |
Nom : DistancePointDroite | Description : Retourne la distance minimale entre un point px,py et une ligne x1,y1,x2,y2. Les variables ix et iy fournies en paramètres prennent alors la valeur du point de la ligne correspondant. La variable U compris entre 0 et 1 indique que le point le plus proche est sur le segment x1,y1,x2,y2. Si U < 0 le point est avant x1,y1 et pour U > 0 après x2,y2. On peut recalculer ix,iy avec U de cette manière : ix = x1 + U * (x2-x1) iy = y1 + U * (y2-y1) |
Listing : Function DistancePointDroite( x1#, y1#, x2#, y2#, px#, py#, ByRef ix#, ByRef iy#, ByRef U#) As Double ' Distance point / droite Local Double h h = Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2) If h NEAR 0 ix = (x1 + x2) / 2 : iy = (y1 + y2) / 2 Return Sqr((ix - px) ^ 2 + (iy - py) ^ 2) EndIf U = (((px - x1) * (x2 - x1)) + ((py - y1) * (y2 - y1))) U = U / (h ^ 2) ix = x1 + U * (x2 - x1) iy = y1 + U * (y2 - y1) Return Sqr((ix - px) ^ 2 + (iy - py) ^ 2) End Function |
Nom : Interpolation3pXYZ | Description : A partir d'un triangle 3d Retourne la coordonnées z en fonction d'un point x,y |
Listing : Proc Interpolation3pXYZ(x1#, y1#, z1#, x2#, y2#, z2#, x3#, y3#, z3#, x4#, y4#, ByRef z4#) Local Double xn, yn, zn 'Contributeur : larnicebafteur sur https://www.developpez.ney ' Coordonnées du vecteur normal au plan ABC (par produit vectoriel) xn = (y2 - y1) * (z3 - z1) - (y3 - y1) * (z2 - z1) yn = (x3 - x1) * (z2 - z1) - (x2 - x1) * (z3 - z1) zn = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) 'A partir des coordonnées du vecteur normal et des coordonnées d'un vecteur AM du plan ABC 'Par produit scalaire, on obtient l'équation cartesienne du plan. 'Connaissant x4 et y4, on trouve z4 : z4 = (x1 * xn + y1 * yn + z1 * zn - x4 * xn - y4 * yn) / zn EndProc |
Nom : IntersectionDroites | Description : Retourne True quand il y a intersection entre les 2 droites définies par les segment x1,y1,x2,y2 et x3,y3,x4,y4 Le point d'intersection est alors ix,iy ua < 0 quand le point est en dehors du segment avant x1,y1. ua > 0 quand le point est en dehors du segment après x2,y2. ua compris entre 0 et 1 pour un point situé dans le 1er segment Même chose avec ub pour le second segment |
Listing : Function IntersectionDroites(x1#, y1#, x2#, y2#, x3#, y3#, x4#, y4#, ByRef ix#, ByRef iy# , ByRef Ua#, ByRef Ub#) Local Double Lx2, Lx1, Ly3, Lx3, Ly1, Ly2, S, M1, M2 Lx1 = x2 - x1 Ly1 = y2 - y1 Lx2 = x4 - x3 Ly2 = y4 - y3 M1 = Lx2 * Ly1 M2 = Ly2 * Lx1 S = M2 - M1 If S <> 0 ' Si les lignes ne sont pas parallèles Ly3 = y1 - y3 Lx3 = x1 - x3 Ua = ( Lx2 * Ly3 - Ly2 * Lx3 ) / S Ub = ( Lx1 * Ly3 - Ly1 * Lx3 ) / S ix = x1 + Ua * Lx1 iy = y1 + Ua * Ly1 Return True EndIf Return False EndFunc |
Nom : PointDansAngle3p | Description : Retourn True si le point px,py est dans l'angle formé par x1,y1,x2,y2,x3,y3. L'angle est en x2,y2. Le résultat tient compte des angles ouverts (>180°) |
Listing : Function PointDansAngle3p(x1#, y1#, x2#, y2#, x3#, y3#, px#, py#) As Boolean If ((x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1)) >= 0 If ((px - x2) * (y1 - y2) - (py - y2) * (x1 - x2)) <= 0 If ((px - x2) * (y3 - y2) - (py - y2) * (x3 - x2)) >= 0 Return True EndIf EndIf Else If ((px - x2) * (y1 - y2) - (py - y2) * (x1 - x2)) <= 0 If ((px - x2) * (y3 - y2) - (py - y2) * (x3 - x2)) >= 0 Return True Else If ((px - x2) * (y2 - y3) - (py - y2) * (x2 - x3)) >= 0 Return True EndIf Else If ((px - x2) * (y2 - y1) - (py - y2) * (x2 - x1 )) <= 0 If ((px - x2) * (y3 - y2) - (py - y2) * (x3 - x2 )) >= 0 Return True EndIf EndIf EndIf Return False EndFunc |
Nom : TextToClipBoard | Description : Copie une chaine de caractères dans le presse-papier. |
Listing : Function TextToClipBoard(T As String) As Boolean Local Long Adr Local Int HWND Local Handle hMem If Me Is Nothing HWND = 0 Else HWND = Me.hWnd EndIf Local hOwnerWnd As Int Local hResult As Int If OpenClipboard(HWND) ~EmptyClipboard() hMem = GlobalAlloc(GPTR, Len(T) + 1) Adr = GlobalLock(hMem) MemCpy(V:T, Adr, Len(T)) ~GlobalUnlock(hMem) ~SetClipboardData(CF_OEMTEXT, hMem) ~CloseClipboard() Return True Else Return False EndIf EndFunc |
Nom : TranspositionTriangulaire | Description : On fournit en paramètre les coordonnées de 2 triangles et un point (px,py) dans le premier triangle (qui peut aussi être en dehors). La procédure retourne la position ix,iy du point correspondant dans le 2ème triangle. |
Listing : Proc TranspositionTriangulaire(x1#, y1#, x2#, y2#, x3#, y3#, x4#, y4#, x5#, y5#, x6#, y6#, px#, py#, ByRef ix#, ByRef iy#) Local Double bx, by, bx2, by2, h, ua , ub, lx, ly Local Int Cas Local Double Lx2, Lx1, Ly3, Lx3, Ly1, Ly2, S, M1, M2, m For Cas = 1 To 3 // 3 Cas de figures où le segment de projection depuis P2 peut être parallèle à P1 P3. Lx1 = px - x2 Ly1 = py - y2 Lx2 = x3 - x1 Ly2 = y3 - y1 M1 = Lx2 * Ly1 M2 = Ly2 * Lx1 S = M2 - M1 If S <> 0 // Si les lignes ne sont pas parallèles on calcule la transposition et on sort de la boucle Ly3 = y2 - y1 Lx3 = x2 - x1 ua = ( Lx2 * Ly3 - Ly2 * Lx3 ) / S ub = ( Lx1 * Ly3 - Ly1 * Lx3 ) / S bx = x2 + ua * Lx1 by = y2 + ua * Ly1 bx2 = x4 + (x6 - x4) * ub by2 = y4 + (y6 - y4) * ub ix = x5 iy = y5 lx = bx - x2 ly = by - y2 If lx <> 0 m = (px - x2) / lx ix = x5 + (bx2 - x5) * m iy = y5 + (by2 - y5) * m Else If ly <> 0 m = (py - y2) / ly ix = x5 + (bx2 - x5) * m iy = y5 + (by2 - y5) * m EndIf Exit For Else If Cas = 1 Swap x2, x3 Swap y2, y3 Swap x5, x6 Swap y5, y6 Else Swap x1, x2 Swap y1, y2 Swap x4, x5 Swap y4, y5 EndIf EndIf Next Cas EndProc |