G
Guest
I am a scientist with a background in Fortran programming which
occasionally works in Java. I recently had the need to make some
trigonometric computations like :
x=(pxy[0]-crpix1)*cdelt1 ;
y=(pxy[1]-crpix2)*cdelt2 ;
phi =Math.PI-Math.atan2(y,x) ;
theta=Math.atan(1./(Math.sqrt(x*x+y*y)*Math.PI/180.)) ;
cv1=Math.toRadians(crval1) ;
cv2=Math.toRadians(crval2) ;
radec[1]=Math.asin(Math.sin(theta)*Math.sin(cv2)-Math.cos(theta)*Math.cos(phi)*Math.cos(cv2)) ;
radec[0]=cv1+Math.asin(Math.cos(theta)*Math.sin(phi)/Math.cos(radec[1])) ;
radec[0]=Math.toDegrees(radec[0]);
radec[1]=Math.toDegrees(radec[1]);
I have import java.lang.Math ; at the beginning of my program.
Is it really necessary that I prefix all invocation of trigonometric
functions with "Math." ? It there any way to do that implicitly like in
the following (not working) example ?
I won't care about specifying numeric constants as Math.PI, but the
notation above seems rather heavy to me.
x=(pxy[0]-crpix1)*cdelt1 ;
y=(pxy[1]-crpix2)*cdelt2 ;
phi =Math.PI-atan2(y,x) ;
theta=atan(1./(sqrt(x*x+y*y)*Math.PI/180.)) ;
cv1=toRadians(crval1) ;
cv2=toRadians(crval2) ;
radec[1]=asin(sin(theta)*sin(cv2)-cos(theta)*cos(phi)*cos(cv2)) ;
radec[0]=cv1+asin(cos(theta)*sin(phi)/cos(radec[1])) ;
radec[0]=toDegrees(radec[0]);
radec[1]=toDegrees(radec[1]);
occasionally works in Java. I recently had the need to make some
trigonometric computations like :
x=(pxy[0]-crpix1)*cdelt1 ;
y=(pxy[1]-crpix2)*cdelt2 ;
phi =Math.PI-Math.atan2(y,x) ;
theta=Math.atan(1./(Math.sqrt(x*x+y*y)*Math.PI/180.)) ;
cv1=Math.toRadians(crval1) ;
cv2=Math.toRadians(crval2) ;
radec[1]=Math.asin(Math.sin(theta)*Math.sin(cv2)-Math.cos(theta)*Math.cos(phi)*Math.cos(cv2)) ;
radec[0]=cv1+Math.asin(Math.cos(theta)*Math.sin(phi)/Math.cos(radec[1])) ;
radec[0]=Math.toDegrees(radec[0]);
radec[1]=Math.toDegrees(radec[1]);
I have import java.lang.Math ; at the beginning of my program.
Is it really necessary that I prefix all invocation of trigonometric
functions with "Math." ? It there any way to do that implicitly like in
the following (not working) example ?
I won't care about specifying numeric constants as Math.PI, but the
notation above seems rather heavy to me.
x=(pxy[0]-crpix1)*cdelt1 ;
y=(pxy[1]-crpix2)*cdelt2 ;
phi =Math.PI-atan2(y,x) ;
theta=atan(1./(sqrt(x*x+y*y)*Math.PI/180.)) ;
cv1=toRadians(crval1) ;
cv2=toRadians(crval2) ;
radec[1]=asin(sin(theta)*sin(cv2)-cos(theta)*cos(phi)*cos(cv2)) ;
radec[0]=cv1+asin(cos(theta)*sin(phi)/cos(radec[1])) ;
radec[0]=toDegrees(radec[0]);
radec[1]=toDegrees(radec[1]);