 # How to properly point Sun?

I prepared a Cesium sandcastle example based on this answer from @FSimardGIS, but something is going wrong: only one of many rays correctly points to the Sun, the other appears random. What’s wrong here?
I took the test coordinates from SunCalc library, but you can also insert data manually, using for example this site for calculations:

This is the source code from the other answer:

``````function CalcPosFromAltAzDist(startPoint, vectorPointing) {
var ellipsoid = Cesium.Ellipsoid.WGS84;
var ENU = new Cesium.Matrix4();
Cesium.Transforms.eastNorthUpToFixedFrame(startPoint,ellipsoid,ENU);
var myX = vectorPointing.dist * Math.sin(vectorPointing.az * Math.PI / 180);
var myY = vectorPointing.dist * Math.cos(vectorPointing.az * Math.PI / 180);
var myZ = vectorPointing.dist * Math.sin(vectorPointing.alt * Math.PI / 180);
var offset = new Cesium.Cartesian3(myX,myY,myZ);
var finalPoint = Cesium.Matrix4.multiplyByPoint(ENU, offset, new Cesium.Cartesian3());
return finalPoint;
}
``````

Call with:

``````vectorPointing= {"alt" : 30, "az" : 0};
startPoint= Cesium.Cartesian3.fromDegrees(290.6, -35.78);
``````

You can also find the sun position with Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame and input that as the other end of your polyline.