-
Notifications
You must be signed in to change notification settings - Fork 13
/
quadrilaterals.go
146 lines (117 loc) · 3.34 KB
/
quadrilaterals.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//for quardrelaterals
package gogeom
import (
"math"
)
//sides of square
type SquareSides struct {
Side float64
}
//diagonals of square
type SquareDiagonals struct {
Diagonal float64
}
//sides of rectangle
type RectangleSides struct {
Length, Breadth float64
}
//sides of parallelogram
type ParallelogramSides struct {
Base, Slant, Height float64
}
//sides of trapezium with height
type TrapeziumSidesWithHeight struct {
Base, Top, Height float64
}
//sides of trapezium slants
type TrapeziumSidesWithSlants struct {
Base, Top, Slant1, Slant2 float64
}
//diagonals of rhombus
type RhombusDiagonals struct {
Diagonal1, Diagonal2 float64
}
//sides and height of rhombus
type RhombusSides struct {
Side, Height float64
}
//sides of scalene quadrilateral
type ScaleneQuadrilateralSides struct {
Side1, Side2, Side3, Side4 float64
}
//perimeter of square when the sides are there
func (q *SquareSides) PerimeterOfSquare() float64 {
return 4 * q.Side
}
//area of the square when the sides are there
func (q *SquareSides) AreaOfSquare() float64 {
return math.Pow(q.Side,2)
}
//diagonal of the square when the side is there
func (q *SquareSides) DiagonalOfSquare() float64 {
return math.Sqrt(2) * q.Side
}
//side of the square when diagonal is there
func (q *SquareDiagonals) SideOfSquare() float64 {
return q.Diagonal / math.Sqrt(2)
}
//perimeter of the square when the diagonals are there
func (q *SquareDiagonals) PerimeterOfSquare() float64 {
return 4 * q.SideOfSquare()
}
//area of the square when the diagonals are there
func (q *SquareDiagonals) AreaOfSquare() float64 {
return math.Pow(q.SideOfSquare(), 2)
}
//perimeter of rectangle
func (q *RectangleSides) PerimeterOfRectangle() float64 {
return 2 * (q.Length + q.Breadth)
}
//area of rectangle
func (q *RectangleSides) AreaOfRectangle() float64 {
return q.Length * q.Breadth
}
//diagonal of rectangle
func (q *RectangleSides) DiagonalOfRectangle() float64 {
return math.Sqrt(math.Pow(q.Length, 2) + math.Pow(q.Breadth, 2))
}
//perimeter of parallelogram
func (q *ParallelogramSides) PerimeterOfParallelogram() float64 {
return 2 * (q.Base + q.Slant)
}
//area of parallelogram
func (q *ParallelogramSides) AreaOfParallelogram() float64 {
return q.Base * q.Height
}
//area of trapezium
func (q *TrapeziumSidesWithHeight) AreaOfTrapezium() float64 {
return 0.5 * (q.Base + q.Top) * q.Height
}
//perimeter of trapezium
func (q *TrapeziumSidesWithSlants) PerimeterOfTrapezium() float64 {
return q.Base + q.Top + q.Slant1 + q.Slant2
}
//area of rhombus with diagonals given
func (q *RhombusDiagonals) AreaOfRhombus() float64 {
return 0.5 * q.Diagonal1 * q.Diagonal2
}
//length of each side of rhombus with diagonals given
func (q *RhombusDiagonals) LengthOfRhombusSides() float64 {
return 0.5 * math.Sqrt(math.Pow(q.Diagonal1, 2) + math.Pow(q.Diagonal2, 2))
}
//perimeter of rhombus with diagonals given
func (q *RhombusDiagonals) PerimeterOfRhombus() float64 {
return 4 * q.LengthOfRhombusSides()
}
//area of rhombus with sides and height given
func (q *RhombusSides) AreaOfRhombus() float64 {
return q.Side * q.Height
}
//perimeter of rhombus with sides and height given
func (q *RhombusSides) PerimeterOfRhombus() float64 {
return 4 * q.Side
}
//perimeter of scalene quadrilateral
func (q *ScaleneQuadrilateralSides) PerimeterOfScaleneQuadrilateral() float64 {
return q.Side1 + q.Side2 + q.Side3 + q.Side4
}