Skip to content

Commit

Permalink
draft 1 of triangle/sas algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
gwdean committed Sep 28, 2011
1 parent 7657b84 commit cde65cf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gwdean/journal.org
Expand Up @@ -282,6 +282,12 @@ var ctx = canvas.getContext('2d');


An Explanation will follow later. An Explanation will follow later.
** Testing? ** Testing?

* 11/09/28 -> Completed second part of the algorithm.
Made a simple change to the algorithm, extending it
to cover triangles which have angle values of greater
than 90 degrees. I am saving this as a new file called
my-triangle-sas.js.
* Reference * Reference
--------- ---------
** Whalesong README ** Whalesong README
Expand Down
56 changes: 56 additions & 0 deletions gwdean/my-triangle-sas.js
@@ -0,0 +1,56 @@
// These two functions represent the first draft of a workable
// triangle/sas function for Whalesong. They need to be cleaned
// up and tested, but the basic logic seems to work.

function drawLessThan90(){
var canvas = document.getElementById('1');
if (canvas.getContext){

var ctx = canvas.getContext('2d');
var x = 50;
var y = 50;
var a = 100;
var b = 10;
var c = 50;
var radians = b * 0.0174532952;
var height = a * Math.sin(radians);
var width = Math.sqrt((a * a) - (height * height));

// works for <90

ctx.beginPath();
ctx.moveTo(x,y);
ctx.lineTo(c+x,y);
ctx.lineTo((c-width)+x,height+y);
ctx.lineTo(x,y);
ctx.fill();
}

}


function drawGreaterThan90(){
var canvas = document.getElementById('2');
if (canvas.getContext){

var ctx = canvas.getContext('2d');
var x = 50;
var y = 50;
var a = 100;
var b = 150;
var c = 50;
var radians = b * 0.0174532952;
var height = a * Math.sin(radians);
var width = Math.sqrt((a * a) - (height * height));

// works for >90

ctx.beginPath();
ctx.moveTo(x,y);
ctx.lineTo(c+x,y);
ctx.lineTo((c+width)+x,height+y);
ctx.lineTo(x,y);
ctx.fill();
}

}

0 comments on commit cde65cf

Please sign in to comment.