# How to calculate when the camera field of view intersects the horizon?

I’d like to be able to compute when a tumbling satellite will be able to photograph the horizon given camera sensor parameters, and the satellite’s initial attitude and angular velocity. What are the best tools to use in Orekit to accomplish this?

Thanks!

You will need to set up a custom horizon event detector, configured with an implementation of `FieldOfView` (most probably `DoubleDihedraFieldOfView`) and an instance of `OneAxisEllipsoid`. In order to implement `HorizonDetector`, the simplest way is to make it extend the abstract class `AbstractDetector` so the only two metods you have to implement will be a protected `create` factory method and the core computation method: the `g` switching function.

For a simple example of how to set up the constructors and the `create` factory method, just look at a simple existing detector, like `AltitudeDetector` for example.

The `g` function is the more difficult part. Its specification is that the event occur when the sign of this function changes. In your case, I would suggest the following approach to implement the g function.

1. using the current `SpacecraftState` provided as an argument to the `g` function, the internally
stored `OneAxisEllipsoid` and an internally stored angular step, build a list of target points that
will sample limb of the ellipsoid as seen from the spacecraft, in spacecraft frame (there is
a `pointOnLimb` method in `Ellipsoid`, which is the parent class of `OneAxisEllipsoid` that may
help you, you will still need to do some frames transforms to get it in spacecraft frame)
2. for each of the sample targets, call the `offsetFromBoundary` method from the `FieldOfView`
interface with a line of sight computed from the sample point and a radius set to 0 (the
`VisibilityTrigger` will have no effect here, so you can select one arbitrarily)
3. the value of the g function should be set to the minimum of all offsets computed from
all sample points