10. november 2013 - 12:21Der er
6 kommentarer og 1 løsning
Oversætte kode fra C til VB.NET
Hej
Er der nogen der kan oversætte følgende kode for mig til VB.NET ?
På forhånd tak !
/jpi
// Globals which should be set before calling this function: // // int polySides = how many corners the polygon has // float polyX[] = horizontal coordinates of corners // float polyY[] = vertical coordinates of corners // float x, y = point to be tested // // (Globals are used in this example for purposes of speed. Change as // desired.) // // The function will return YES if the point x,y is inside the polygon, or // NO if it is not. If the point is exactly on the edge of the polygon, // then the function may return YES or NO. // // Note that division by zero is avoided because the division is protected // by the "if" clause which surrounds it.
bool pointInPolygon() {
int i, j=polySides-1 ; bool oddNodes=NO ;
for (i=0; i<polySides; i++) { if (polyY[i]<y && polyY[j]>=y || polyY[j]<y && polyY[i]>=y) { if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x) { oddNodes=!oddNodes; }} j=i; }
' Globals which should be set before calling this function: ' ' int polySides = how many corners the polygon has ' float polyX[] = horizontal coordinates of corners ' float polyY[] = vertical coordinates of corners ' float x, y = point to be tested ' ' (Globals are used in this example for purposes of speed. Change as ' desired.) ' ' The function will return YES if the point x,y is inside the polygon, or ' NO if it is not. If the point is exactly on the edge of the polygon, ' then the function may return YES or NO. ' ' Note that division by zero is avoided because the division is protected ' by the "if" clause which surrounds it.
Private Function pointInPolygon() As Boolean
Dim i As Integer, j As Integer = polySides - 1 Dim oddNodes As Boolean = NO
For i = 0 To polySides - 1 If polyY(i) < y AndAlso polyY(j) >= y OrElse polyY(j) < y AndAlso polyY(i) >= y Then If polyX(i) + (y - polyY(i)) / (polyY(j) - polyY(i)) * (polyX(j) - polyX(i)) < x Then oddNodes = Not oddNodes End If End If j = i Next
Ok, og enig med Arne at C og C# er ret forskellige, men til den opgave kunne det nok række.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.