Calculate the solar elevation angle of surface points in java

I return a negative value when calculating the solar altitude angle, I don’t know why.

This is my fanction:

public double getSunElevation(GeodeticPoint nadirPoint, AbsoluteDate currentDate) {
TopocentricFrame topoFrame = new TopocentricFrame(earth, nadirPoint, “topo”);
TimeStampedPVCoordinates sunInTopo = sun.getPVCoordinates(currentDate, topoFrame);
Vector3D sunDirection = sunInTopo.getPosition();
double elevation = FastMath.asin(sunDirection.getZ() / sunDirection.getNorm());
return FastMath.toDegrees(elevation);
}

Note that TopocentricFrame already has a builtin getElevation method.
May be the Sun is below horizon at this date?

Yes, I used
double sunEvelation = topoFrame.getElevation(sunDirection, topoFrame, currentDate);
and got the same value, can I simpled to abs it?

A negative sun elevation angle means the Sun is below the local horizon; it has nothing to do with taking absolute or not. If you’re certain the Sun is above the local horizon at this time, you should recheck your code.