-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw1
27 lines (25 loc) · 804 Bytes
/
hw1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function Point(x,y){
this.x = x;
this.y = y;
this.getDistance = function(point){
var XDistance = this.x - point.x;
var YDistance = this.y - point.y;
return Math.sqrt(Math.pow(XDistance,2)+Math.pow(YDistance,2));
}
}
n Triangle(p1,p2,p3){
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
var d12 = p1.getDistance(p2);
var d13 = p1.getDistance(p3);
var d23 = p2.getDistance(p3);
this.getPerimeter = function(){
var perimeter = d12+d23+d13;
return perimeter;
}
this.getArea = function() {
var semiperimeter = this.getPerimeter()/2;
return Math.sqrt(semiperimeter*(semiperimeter - d12)*(semiperimeter - d23)*(semiperimeter - d13));
}
}