package
hans_gis.coord
{
public
class
CoordsTransform
{
public
function
CoordsTransform()
{
}
public
function
CartesianToSpherical(coord:CartesianCoord):SphericalCoord{
var
radius =
this
.GetModuloFromCartesianCoord(coord);
var
theta =
this
.GetThetaFromCartesianCoord(coord);
var
phi =
this
.GetPhiFromCartesianCoord(coord);
return
new
SphericalCoord(radius, theta, phi);
}
protected
function
GetModuloFromCartesianCoord(coord:CartesianCoord):
Number
{
return
Math.sqrt( coord.x*coord.x + coord.y*coord.y + coord.z*coord.z );
}
protected
function
GetThetaFromCartesianCoord(coord:CartesianCoord):
Number
{
// return Math.atan(Math.sqrt(coord.x*coord.x + coord.y*coord.y)/coord.z);
return
Math.acos(coord.z/
this
.GetModuloFromCartesianCoord(coord));
}
protected
function
GetPhiFromCartesianCoord(coord:CartesianCoord):
Number
{
return
Math.atan(coord.y/coord.x);
}
public
function
SphericalToCartesian(coord:SphericalCoord):CartesianCoord{
var
x =
this
.GetXFromSphericalCoord(coord);
var
y =
this
.GetYFromSphericalCoord(coord);
var
z =
this
.GetZFromSphericalCoord(coord);
return
new
CartesianCoord(x, y, z);
}
protected
function
GetXFromSphericalCoord(coord:SphericalCoord):
Number
{
return
coord.radius*Math.sin(coord.theta)*Math.cos(coord.phi);
}
protected
function
GetYFromSphericalCoord(coord:SphericalCoord):
Number
{
return
coord.radius*Math.sin(coord.theta)*Math.sin(coord.phi);
}
protected
function
GetZFromSphericalCoord(coord:SphericalCoord):
Number
{
return
coord.radius*Math.cos(coord.theta);
}
}
}
联系客服