-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrhombus.c
More file actions
42 lines (39 loc) · 825 Bytes
/
rhombus.c
File metadata and controls
42 lines (39 loc) · 825 Bytes
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
#include "rhombus.h"
// length of vectors 1>2, 2>3, 3>4, 4>1, 1>3, 2>4
float side(struct rhombus R, char what) {
float x, y;
if(what == '1') {
x = R.x1 - R.x2;
y = R.y1 - R.y2;
}
if(what == '2') {
x = R.x2 - R.x3;
y = R.y2 - R.y3;
}
if(what == '3') {
x = R.x3 - R.x4;
y = R.y3 - R.y4;
}
if(what == '4') {
x = R.x4 - R.x1;
y = R.y4 - R.y1;
}
if(what == '5') {
x = R.x1 - R.x3;
y = R.y1 - R.y3;
}
if(what == '6') {
x = R.x2 - R.x4;
y = R.y2 - R.y4;
}
return sqrtf(x * x + y * y);
}
float S(struct rhombus R) {
float d1 = side(R, '5');
float d2 = side(R, '6');
return (d1 * d2) / 2;
}
float P(struct rhombus R) {
float a = side(R, '1');
return 4 * a;
}