1 /*
2 * Copyright (c) 2019 Kevin Townsend (KTOWN)
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <math.h>
8 #include <errno.h>
9 #include <zsl/zsl.h>
10 #include <zsl/physics/work.h>
11
12 int
zsl_phy_work_module(zsl_real_t f,zsl_real_t d,zsl_real_t * w)13 zsl_phy_work_module(zsl_real_t f, zsl_real_t d, zsl_real_t *w)
14 {
15 if (f < 0 || d < 0) {
16 *w = NAN;
17 return -EINVAL;
18 }
19
20 *w = f * d;
21
22 return 0;
23 }
24
25 int
zsl_phy_work_x(zsl_real_t f,zsl_real_t d,zsl_real_t theta,zsl_real_t * w)26 zsl_phy_work_x(zsl_real_t f, zsl_real_t d, zsl_real_t theta, zsl_real_t *w)
27 {
28 if (f < 0 || d < 0) {
29 *w = NAN;
30 return -EINVAL;
31 }
32
33 zsl_phy_work_module(f, d, w);
34
35 *w *= ZSL_COS(theta);
36
37 return 0;
38 }
39
40 int
zsl_phy_work_y(zsl_real_t f,zsl_real_t d,zsl_real_t theta,zsl_real_t * w)41 zsl_phy_work_y(zsl_real_t f, zsl_real_t d, zsl_real_t theta, zsl_real_t *w)
42 {
43 if (f < 0 || d < 0) {
44 *w = NAN;
45 return -EINVAL;
46 }
47
48 zsl_phy_work_module(f, d, w);
49
50 *w *= ZSL_SIN(theta);
51
52 return 0;
53 }
54
55 int
zsl_phy_work_kin(zsl_real_t k1,zsl_real_t k2,zsl_real_t * w)56 zsl_phy_work_kin(zsl_real_t k1, zsl_real_t k2, zsl_real_t *w)
57 {
58 *w = k2 - k1;
59
60 return 0;
61 }
62