<!--

function setEq(eqstr, eqStps, n)
{
    var elm = document.getElementById("eqn");
    if (elm != null) {elm.innerHTML = eqstr;}
    elm = document.getElementById("eqstp");
    if (elm != null) {elm.innerHTML = "";}
    for (var i = 0; i < n; i++)
    {
        if (elm != null) 
        {
            var chld = elm.appendChild(document.createElement('div'));
            if (chld != null) {chld.innerHTML = eqStps[i]}
        }
    }
}



function roundme(x) {return Math.round(x*1000)/1000;}



function getrand(min, max)
{
  rnd = Math.floor(Math.random()*1000);
  rnd = rnd % (max-min+1);
  return min + rnd;
}

function getVal(x)
{
    var xval = Number.NaN;
    try
    {
        xval = parseFloat(x);
    }
    catch (e) {return Number.NaN;}
    
    return xval;
}

function solvePt()
{
    var ptx = getVal(document.rotpt_frm.ptx.value); if (isNaN(ptx)) {alert("Invalid value for X");return false;}
    var pty = getVal(document.rotpt_frm.pty.value); if (isNaN(pty)) {alert("Invalid value for Y");return false;}
    var ptr = getVal(document.rotpt_frm.ptr.value); if (isNaN(ptr)) {alert("Invalid value for rotation");return false;}
    var ptx1 = getVal(document.rotpt_frm.ptx1.value); if (isNaN(ptx1)) {alert("Invalid value for reference X");return false;}
    var pty1 = getVal(document.rotpt_frm.pty1.value); if (isNaN(pty1)) {alert("Invalid value for reference Y");return false;}
    var refpt = "the origin";var isref = false;
    if (ptx1 != 0 || pty1 != 0) {refpt = "another point Q(" + ptx1 + ", " + pty1 + ")";isref=true;}
    var eqstr = "Rotate a point P(" + ptx + ", " + pty + ") by " + ptr + "&deg; about " + refpt;
    var n = 0;var nptx = ptx; var npty = pty;var sub="";
    var eqStps = Array(20);
    var x1str = ptx1 < 0 ? "(" + ptx1 + ")" : ptx1;
    var y1str = pty1 < 0 ? "(" + pty1 + ")" : pty1;
    if (isref)
    {
        eqStps[n] = "As the reference point is not origin, subtract reference point coordinates from the coordinates of the point to be rotated.(i.e. Think of this reference point as the origin)";
        n++;
        eqStps[n] = "i.e. X coordinate = " + ptx + " - " + x1str + " and Y coordinate = " + pty + " - " + y1str;
        n++;
        nptx = ptx - ptx1; npty = pty - pty1;
        eqStps[n] = "So our new point P<sub>&sup1;</sub> is P<sub>&sup1;</sub>(" + nptx + ", " + npty + ")<br>";
        n++;
        sub = "<sub>&sup1;</sub>";
    }
    var ptrx = 0; var ptry = 0;
    
    if (ptr == 90)
    {
        eqStps[n] = "The simple rule for rotation by 90&deg; about the origin is P" + sub + "(X,Y) becomes P" + sub + "<sup>&sup1</sup>(-Y, X)";    
        n++;
        ptrx = -1 * npty; ptry = nptx;
    }
    else if (ptr == 180)
    {
        eqStps[n] = "The simple rule for rotation by 180&deg; about the origin is P" + sub + "(X,Y) becomes P" + sub + "<sup>&sup1</sup>(-X, -Y)";    
        n++;
        ptrx = -1 * nptx; ptry = -1*npty;
    }
    else if (ptr == 270)
    {
        eqStps[n] = "The simple rule for rotation by 270&deg; about the origin is P" + sub + "(X,Y) becomes P" + sub + "<sup>&sup1</sup>(Y, -X)";    
        n++;
        ptrx = npty; ptry = -1*nptx;
    }
    else
    {
        eqStps[n] = "For angles other than 90,180,270 the X Coordinate of rotated point X<sup>&sup1;</sup> = X*Cos(&theta;) - Y*Sin(&theta;)";    
        n++;
        eqStps[n] = "For angles other than 90,180,270 the Y Coordinate of rotated point Y<sup>&sup1;</sup> = X*Sin(&theta;) + Y*Cos(&theta;)";    
        n++;
        eqStps[n] = "(Where &Theta; is the rotation angle and * is used for multiplication symbol).";    
        n++;
        eqStps[n] = "X<sup>&sup1;</sup> = " + nptx + "*Cos(" + ptr + "&deg;) - " + npty + "*Sin(" + ptr + "&deg;)"; 
        n++;
        eqStps[n] = "Y<sup>&sup1;</sup> = " + nptx + "*Sin(" + ptr + "&deg;) + " + npty + "*Cos(" + ptr + "&deg;)"; 
        n++;
        var rd = (Math.PI * ptr)/180;
        ptrx = roundme(nptx * Math.cos(rd) - npty * Math.sin(rd));
        ptry = roundme(nptx * Math.sin(rd) + npty * Math.cos(rd));
    }
    
    if (isref)
    {
        eqStps[n] = "i.e. Our new rotated point coordinates are P" + sub + "<sup>&sup1;</sup>(" + ptrx + ", " + ptry + ")<br><br>";
        n++;
        eqStps[n] = "Now let's add the reference point coordinates to the rotated point";
        n++;
        eqStps[n] = "i.e. our rotated point P<sup>&sup1;</sup> coordinates are X = " + ptrx + " + " + x1str + " and Y = " + ptry + " + " + y1str;
        n++;
        ptrx = roundme(ptrx + ptx1);
        ptry = roundme(ptry + pty1);
    }
    
    eqStps[n] = "<b>The Rotated point P<sup>&sup1;</sup> is P<sup>&sup1;</sup>(" + ptrx + ", " + ptry + ")</b>";
    n++;
    
    setEq(eqstr,eqStps,n);
}

function getws()
{
    var useorg = document.rotpt_frm.ptref[0].checked;
    var rotang = 0;
    for (var i = 1; i < 7; i++)
    {
        var chkobj = document.getElementById("ptr" + i);
        if (chkobj != null) {if(chkobj.checked){rotang += 1*chkobj.value;}}
    }
    var obj = document.getElementById("hdnvrbl");
    if (obj != null)
    {
        var tbd='tbd';
        var chld = obj.appendChild(document.createElement('div')); 
        if (chld != null) {chld.innerHTML = "<input type=hidden name=rotang value=" + rotang + ">";}
        chld = obj.appendChild(document.createElement('div')); 
        if (chld != null) {chld.innerHTML = "<input type=hidden name=useorg value=" + (useorg == true ? 1 : 0) + ">";}
    }
    document.rotpt_frm.submit();
}


//-->

