Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -0,0 +1,63 @@
|
|||
BEGIN
|
||||
|
||||
MODE POINT = STRUCT( REAL x, y );
|
||||
|
||||
MODE POLYGON = STRUCT( STRING name, FLEX[ 1 : 0 ]POINT points );
|
||||
PROC contains = ( POLYGON self, POINT p )BOOL:
|
||||
BEGIN
|
||||
BOOL odd := FALSE, REAL eps = 1e-9;
|
||||
PROC rayseg = ( POINT p in, a in, b in )BOOL:
|
||||
BEGIN
|
||||
PROC max = ( REAL m, n )REAL: IF m > n THEN m ELSE n FI;
|
||||
PROC min = ( REAL m, n )REAL: IF m < n THEN m ELSE n FI;
|
||||
POINT p := p in, a := a in, b := b in;
|
||||
IF y OF a > y OF b THEN POINT t = a; a := b; b := t FI;
|
||||
IF y OF p = y OF a OR y OF p = y OF b THEN y OF p+:= eps FI;
|
||||
IF y OF p < y OF a OR y OF p > y OF b OR x OF p > max( x OF a, x OF b )
|
||||
THEN FALSE
|
||||
ELIF x OF p < min( x OF a, x OF b )
|
||||
THEN TRUE
|
||||
ELSE
|
||||
REAL red = IF x OF a = x OF b THEN max real ELSE ( y OF b - y OF a ) / ( x OF b - x OF a ) FI;
|
||||
REAL blu = IF x OF a = x OF p THEN max real ELSE ( y OF p - y OF a ) / ( x OF p - x OF a ) FI;
|
||||
blu >= red
|
||||
FI
|
||||
END # rayseq # ;
|
||||
|
||||
INT len points = ( UPB points OF self - LWB points OF self ) + 1;
|
||||
FOR i FROM LWB points OF self TO UPB points OF self DO
|
||||
POINT a = ( points OF self )[ i ];
|
||||
POINT b = ( points OF self )[ ( i MOD len points ) + 1 ];
|
||||
IF rayseg( p, a, b ) THEN odd := NOT odd FI
|
||||
OD;
|
||||
odd
|
||||
END # contains # ;
|
||||
|
||||
[]POLYGON polygons =
|
||||
( ( "square"
|
||||
, ( ( 0, 0 ), ( 10, 0 ), ( 10, 10 ), ( 0, 10 ) )
|
||||
)
|
||||
, ( "squarehole"
|
||||
, ( ( 0, 0 ), ( 10, 0 ), ( 10, 10 ), ( 0, 10 ), ( 2.5, 2.5 ), ( 7.5, 2.5 ), ( 7.5, 7.5 ), ( 2.5, 7.5 ) )
|
||||
)
|
||||
, ( "strange"
|
||||
, ( ( 0, 0 ), ( 2.5, 2.5 ), ( 0, 10 ), ( 2.5, 7.5 ), ( 7.5, 7.5 ), ( 10, 10 ), ( 10, 0 ), ( 2.5, 2.5 ) )
|
||||
)
|
||||
, ( "hexagon"
|
||||
, ( ( 3, 0 ), ( 7, 0 ), ( 10, 5 ), ( 7, 10 ), ( 3, 10 ), ( 0, 5 ) )
|
||||
)
|
||||
);
|
||||
[]POINT points = ( ( 5, 5 ), (5 , 8 ), ( -10, 5 ), ( 0, 5 ), ( 10, 5 ), ( 8, 5 ), ( 10, 10 ) );
|
||||
|
||||
FOR p FROM LWB polygons TO UPB polygons DO
|
||||
POLYGON poly = polygons[ p ];
|
||||
print(( "Does '", name OF poly, "' contain the point..", newline ) );
|
||||
FOR i FROM LWB points TO UPB points DO
|
||||
POINT pt = points[ i ];
|
||||
print( ( " ( ", fixed( x OF pt, -5, 1 ), ", ", fixed( y OF pt, -5, 1 ), " ) " ) );
|
||||
print( ( IF contains( poly, pt ) THEN " true" ELSE " false" FI, newline ) )
|
||||
OD;
|
||||
print( ( newline ) )
|
||||
OD
|
||||
|
||||
END
|
||||
67
Task/Ray-casting-algorithm/C-sharp/ray-casting-algorithm.cs
Normal file
67
Task/Ray-casting-algorithm/C-sharp/ray-casting-algorithm.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
|
||||
class RayCasting {
|
||||
|
||||
static bool Intersects(int[] A, int[] B, double[] P) {
|
||||
if (A[1] > B[1])
|
||||
return Intersects(B, A, P);
|
||||
|
||||
if (P[1] == A[1] || P[1] == B[1])
|
||||
P[1] += 0.0001;
|
||||
|
||||
if (P[1] > B[1] || P[1] < A[1] || P[0] >= Math.Max(A[0], B[0]))
|
||||
return false;
|
||||
|
||||
if (P[0] < Math.Min(A[0], B[0]))
|
||||
return true;
|
||||
|
||||
double red = (P[1] - A[1]) / (P[0] - A[0]);
|
||||
double blue = (B[1] - A[1]) / (B[0] - A[0]);
|
||||
return red >= blue;
|
||||
}
|
||||
|
||||
static bool Contains(int[][] shape, double[] pnt) {
|
||||
bool inside = false;
|
||||
int len = shape.Length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (Intersects(shape[i], shape[(i + 1) % len], pnt))
|
||||
inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
|
||||
public static void Main(string[] args) {
|
||||
double[][] testPoints = new double[][] {
|
||||
new double[] { 10, 10 }, new double[] { 10, 16 }, new double[] { -20, 10 },
|
||||
new double[] { 0, 10 }, new double[] { 20, 10 }, new double[] { 16, 10 },
|
||||
new double[] { 20, 20 }
|
||||
};
|
||||
|
||||
foreach (int[][] shape in shapes) {
|
||||
foreach (double[] pnt in testPoints)
|
||||
Console.Write($"{Contains(shape, pnt),7} ");
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
readonly static int[][] square = new int[][] {
|
||||
new int[] { 0, 0 }, new int[] { 20, 0 }, new int[] { 20, 20 }, new int[] { 0, 20 }
|
||||
};
|
||||
|
||||
readonly static int[][] squareHole = new int[][] {
|
||||
new int[] { 0, 0 }, new int[] { 20, 0 }, new int[] { 20, 20 }, new int[] { 0, 20 },
|
||||
new int[] { 5, 5 }, new int[] { 15, 5 }, new int[] { 15, 15 }, new int[] { 5, 15 }
|
||||
};
|
||||
|
||||
readonly static int[][] strange = new int[][] {
|
||||
new int[] { 0, 0 }, new int[] { 5, 5 }, new int[] { 0, 20 }, new int[] { 5, 15 },
|
||||
new int[] { 15, 15 }, new int[] { 20, 20 }, new int[] { 20, 0 }
|
||||
};
|
||||
|
||||
readonly static int[][] hexagon = new int[][] {
|
||||
new int[] { 6, 0 }, new int[] { 14, 0 }, new int[] { 20, 10 }, new int[] { 14, 20 },
|
||||
new int[] { 6, 20 }, new int[] { 0, 10 }
|
||||
};
|
||||
|
||||
readonly static int[][][] shapes = new int[][][] { square, squareHole, strange, hexagon };
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import "/fmt" for Fmt
|
||||
import "./fmt" for Fmt
|
||||
|
||||
class RayCasting {
|
||||
static intersects(a, b, p) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue