10

2

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?

1In version 11.3,

`Graphics`Mesh`PointWindingNumber`

seems to have been moved to`Graphics`PolygonUtils`PointWindingNumber`

. – Henrik Schumacher – 2018-05-07T08:58:04.8871You can also use the undocumented

`Graphics`Mesh`PointWindingNumber`

which seems to be just as fast as the compiled version. – rm -rf – 2013-07-15T01:35:17.313