1 #include "system/stacktrace.h"
6 Vec vec(float x, float y)
15 Vec vec_from_polar(float arg, float mag)
17 return vec_scala_mult(
18 vec(cosf(arg), sinf(arg)),
22 Vec vec_from_ps(Point p1, Point p2)
33 return atan2f(v.y, v.x);
38 return sqrtf(v.x * v.x + v.y * v.y);
41 Vec vec_sum(Vec v1, Vec v2)
50 Vec vec_sub(Vec v1, Vec v2)
69 float vec_length(Vec v)
71 return sqrtf(v.x * v.x + v.y * v.y);
74 void vec_add(Vec *v1, Vec v2)
80 Vec vec_scala_mult(Vec v, float scalar)
89 Vec vec_entry_mult(Vec v1, Vec v2)
99 Vec vec_entry_div(Vec v1, Vec v2)
109 float rad_to_deg(float a)
114 Point point_mat3x3_product(Point p, mat3x3 m)
116 /* Convert p to Homogeneous coordinates */
117 const float homo_p[3] = {p.x, p.y, 1};
119 /* Transform p with matrix m */
120 const float trans_p[3] = {
121 homo_p[0] * m.M[0][0] + homo_p[1] * m.M[0][1] + homo_p[2] * m.M[0][2],
122 homo_p[0] * m.M[1][0] + homo_p[1] * m.M[1][1] + homo_p[2] * m.M[1][2],
123 homo_p[0] * m.M[2][0] + homo_p[1] * m.M[2][1] + homo_p[2] * m.M[2][2]
126 /* Convert p back to Cartesian coordinates */
127 const Point result_p = {
128 .x = trans_p[0] / trans_p[2],
129 .y = trans_p[1] / trans_p[2]
137 // TODO(#657): math/point/vec_norm: using vec_length is too expensive
138 // It involves multiplication and sqrt. We can just check if its components are close to 0.0f.
140 const float l = vec_length(v);
143 return vec(0.0f, 0.0f);
146 return vec(v.x / l, v.y / l);
149 float vec_sqr_norm(Vec v)
151 return v.x * v.x + v.y * v.y;