Heike gave the following function for winding number:
winding[poly_, pt_] :=
Round[(Total@Mod[(# - RotateRight[#]) &@(ArcTan @@ (pt - #) & /@ poly),
2 Pi, -Pi]/2./Pi)]
I attempted to compile it as follows:
winding2 := Compile[{{poly, _Real, 2}, {pt, _Real, 1}},
Round[(Total@Mod[(# - RotateRight[#]) &@(ArcTan @@ (pt - #) & /@ poly),
2 Pi, -Pi]/2./Pi)]]
Applied to the following simple problem, the compiled version gives error messages:
poly = {{0., 0.}, {10., 0.}, {10., 6.}, {0, 6}, {0., 0.}};
pt = {5., 3.};
winding2[poly, pt]
The error messages include:
Compile::cpapot: Compilation of ArcTan@@(ptCompile`GetElement[poly,System`Private`CompileSymbol[0]])
is not supported for the function argument ArcTan. The only function arguments supported are
Times, Plus, or List. Evaluation will use the uncompiled function. >>
CompiledFunction::cfse: Compiled expression 6.283185307179586` should be a machine-size integer. >>
CompiledFunction::cfex: Could not complete external evaluation at instruction 1;
proceeding with uncompiled evaluation. >>
Where am I going wrong?

Graphics`Mesh`PointWindingNumberwhich seems to be just as fast as the compiled version. – rm -rf Jul 15 '13 at 01:35Graphics`Mesh`PointWindingNumberseems to have been moved toGraphics`PolygonUtils`PointWindingNumber. – Henrik Schumacher May 07 '18 at 08:58