Skip to content
Browse files

draft 1 of triangle/sas algorithm

  • Loading branch information...
1 parent 7657b84 commit cde65cfa7722cf886f91f68df2964fddf4f7193b @gwdean committed
Showing with 62 additions and 0 deletions.
  1. +6 −0 gwdean/journal.org
  2. +56 −0 gwdean/my-triangle-sas.js
View
6 gwdean/journal.org
@@ -282,6 +282,12 @@ var ctx = canvas.getContext('2d');
An Explanation will follow later.
** 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
---------
** Whalesong README
View
56 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.
Something went wrong with that request. Please try again.