var SVGScreen = function(xsize,ysize)
{
this.XSIZE = xsize;
this.YSIZE = ysize;
this.CX = xsize/2;
this.CY = ysize/2;
}
SVGScreen.prototype.radians = function(deg)
{
return deg/180*Math.PI;
}
SVGScreen.prototype.setCircle = function(cx,cy,r)
{
this.CIRCLEX = cx;
this.CIRCLEY = cy;
this.CIRCLER = r;
}
SVGScreen.prototype.setLineStyle = function(width,color)
{
this.WIDTH = width;
this.COLOR = color;
}
SVGScreen.prototype.getHeadSVG = function(){
return '';
}
SVGScreen.prototype.getScrPointAry = function(x,y){
// return [ ((this.CX-x)+"").substring(0,10), ((this.CY-y)+"").substring(0,10) ];
return [ ((x)+"").substring(0,10), ((y)+"").substring(0,10) ];
}
SVGScreen.prototype.getXYZ = function(lamda,fai,L0,B0,P){
var cosB0 = Math.cos( this.radians( B0 ) );
var sinB0 = Math.sin( this.radians( B0 ) );
var cosP = Math.cos( this.radians( P ) );
var sinP = Math.sin( this.radians( P ) );
var L,M,N;
var LD,MD,ND;
var x, y, z;
L = Math.cos( this.radians( fai ) ) * Math.cos( this.radians(lamda-L0));
M = Math.cos( this.radians( fai ) ) * Math.sin( this.radians(lamda-L0));
N = Math.sin( this.radians( fai ) );
LD = cosB0 * L + sinB0 * N;
MD = M;
ND = -sinB0 * L + cosB0 * N;
x = LD;
y = cosP * MD - sinP * ND;
z = sinP * MD + cosP * ND;
return [x,y,z];
}
SVGScreen.prototype.outLine = function(point){
var drawPos = this.getScrPointAry(
point[0][1]*this.CIRCLER+this.CIRCLEX, -point[0][2]*this.CIRCLER+this.CIRCLEY
);
var retStr = ' 0 ){
retStr +=
' L ' + drawPos[0] +" " + drawPos[1];
} else {
retStr +=
' M ' + drawPos[0] +" " + drawPos[1];
}
}
retStr += ' " stroke-width="'+this.WIDTH+'" fill="none" stroke="'+this.COLOR+'" />\n';
return retStr;
}
SVGScreen.prototype.drawCircles = function(L0,B0,P){
// L0 = document.getElementById("L0").value-0;
// B0 = document.getElementById("B0").value-0;
// P = document.getElementById("P").value-0;
var svgHtml = "";
var point;
var lamda = 0;
var fai = 0;
for(fai=-90;fai<=90;fai+=10){
point = new Array();
for(lamda=0;lamda<=360;lamda+=2){
point[lamda/2] = this.getXYZ(lamda,fai,L0,B0,P);
}
svgHtml += this.outLine(point);
}
for(lamda=0;lamda<=360;lamda+=10){
point = new Array();
for(fai=-90;fai<=90;fai+=2){
point[(fai+90)/2] = this.getXYZ(lamda,fai,L0,B0,P);
}
svgHtml += this.outLine(point);
}
return svgHtml;
}
SVGScreen.prototype.getCircle = function(point){
var pflag = false;
var a1,b1,a2,b2;
var ret = new Array();
var xc1 = ( point[1].x - point[0].x )/2.0 + point[0].x ;
var yc1 = ( point[1].y - point[0].y )/2.0 + point[0].y ;
var xc2 = ( point[2].x - point[1].x )/2.0 + point[1].x ;
var yc2 = ( point[2].y - point[1].y )/2.0 + point[1].y ;
if( point[0].y != point[1].y ){
a1 = ( point[1].x - point[0].x ) / ( point[0].y - point[1].y ) ;
b1 = yc1 - a1 * xc1;
} else {
ret[0] = xc1;
pflag = true;
}
if( point[1].y != point[2].y ){
a2 = ( point[2].x - point[1].x ) / ( point[1].y - point[2].y ) ;
b2 = yc2 - a2 * xc2;
} else {
ret[0] = xc2;
a2 = a1;
b2 = b1;
pflag = true;
}
if( !pflag ){
ret[0] = (b2-b1)/(a1-a2);
}
ret[1] = a2 * ret[0] + b2;
ret[2] = Math.sqrt( (point[0].x - ret[0])*(point[0].x - ret[0])
+(point[0].y - ret[1])*(point[0].y - ret[1]) );
return ret;
}
SVGScreen.prototype.outputCircle=function(){
return '\n';
}