Pretend that I have an $W$x$H$ rectangle, inside of which there is a given point. Let's set up coordinates: (0,0) is at the bottom left of the rectangle, and the point is at (x,y), with 0<=x<=W and 0<=y<=H. From this point, I draw a sector of a circle which can be pointing in any direction $\phi$, and has angular width $\theta$ and radius $R$. The sector might have some (or all) of its area outside the rectangle, depending on the configuration and the parameters.
I want an expression, $A(W,H,\theta,\phi,R,x,y)$ for the area of the sector that is inside the rectangle. It will be a piece-wise expression with multiple pieces corresponding to different geometric situations, e.g. the chord of the sector is completely outside the rectangle so the only overlapping area is a part of a triangle, etc.