This commit is contained in:
cfif 2024-12-04 13:10:50 +03:00
commit 9a9bb22c35
3 changed files with 184 additions and 0 deletions

83
Inc/vector.h Normal file
View File

@ -0,0 +1,83 @@
/*
* vector.h
*
* Created on: Mar 4, 2021
* Author: zemon
*/
#ifndef VECTOR_H_
#define VECTOR_H_
#include "stdint.h"
typedef struct {
double x;
double y;
} vector2double;
typedef struct {
float x;
float y;
} vector2;
typedef struct {
uint16_t x;
uint16_t y;
uint16_t z;
} vector3uint16;
typedef struct {
int16_t x;
int16_t y;
int16_t z;
} vector3int16;
typedef struct {
int32_t x;
int32_t y;
int32_t z;
} vector3int32;
typedef struct {
float x;
float y;
float z;
} vector3;
vector3 vector3Add(vector3 one, vector3 two);
vector3 vector3Less(vector3 one, vector3 two);
vector3 vector3DivNum(vector3 vec, float num);
vector3 vector3MultiplyNum(vector3 vec, float num);
float vector3Sum(vector3 vec);
float vector3DotProduct(vector3 first, vector3 second);
float vector3LenSquare(vector3 vec);
float vector3Len(vector3 vec);
vector3 vector3AbsVector(vector3 one);
float vector3AngleCos(vector3 first, vector3 second);
///!!!! VERY EXPENSIVE calculation
float vector3Angle(vector3 first, vector3 second);
vector3 vector3Projection(vector3 one, vector3 two);
vector3int32 vector3Int32Less(vector3int32 one, vector3int32 two);
vector3int32 vector3Int32Add(vector3int32 one, vector3int32 two);
vector3int32 vector3Int32Div(vector3int32 vector, int32_t divider);
vector3int16 vector3Int32toInt16(vector3int32 vector);
vector3int32 vector3int32Abs(vector3int32 one);
#endif /* VECTOR_H_ */

89
Src/vector.c Normal file
View File

@ -0,0 +1,89 @@
/*
* vector.c
*
* Created on: Jun 1, 2021
* Author: zemon
*/
#include "vector.h"
#include "math.h"
vector3 vector3Add(vector3 one, vector3 two) {
return (vector3) {one.x + two.x, one.y + two.y, one.z + two.z};
}
vector3 vector3Less(vector3 one, vector3 two) {
return (vector3) {one.x - two.x, one.y - two.y, one.z - two.z};
}
vector3 vector3DivNum(vector3 vec, float num) {
return (vector3) {vec.x / num, vec.y / num, vec.z / num};
}
vector3 vector3MultiplyNum(vector3 vec, float num) {
return (vector3) {vec.x * num, vec.y * num, vec.z * num};
}
float vector3Sum(vector3 vec) {
return vec.x + vec.y + vec.z;
}
float vector3DotProduct(vector3 first, vector3 second) {
return first.x * second.x + first.y * second.y + first.z * second.z;
}
float vector3LenSquare(vector3 vec) {
return vec.x * vec.x + vec.y * vec.y + vec.z * vec.z;
}
float vector3Len(vector3 vec) {
return sqrt(vector3LenSquare(vec));
}
float floatAbs(float value) {
return value >= 0 ? value : -1 * value;
}
vector3 vector3AbsVector(vector3 one) {
return (vector3) {floatAbs(one.x), floatAbs(one.y), floatAbs(one.z)};
}
float vector3AngleCos(vector3 first, vector3 second) {
return vector3DotProduct(first, second) / (vector3Len(first) * vector3Len(second));
}
///!!!! VERY EXPENSIVE calculation
float vector3Angle(vector3 first, vector3 second) {
return acosf(vector3AngleCos(first, second));
}
vector3 vector3Projection(vector3 projector, vector3 receiver) {
return vector3MultiplyNum(receiver, vector3DotProduct(projector, receiver) / vector3DotProduct(receiver, receiver));
}
vector3int32 vector3Int32Less(vector3int32 one, vector3int32 two) {
return (vector3int32) {one.x - two.x, one.y - two.y, one.z - two.z};
}
vector3int32 vector3Int32Add(vector3int32 one, vector3int32 two) {
return (vector3int32) {one.x + two.x, one.y + two.y, one.z + two.z};
}
vector3int32 vector3Int32Div(vector3int32 vector, int32_t divider) {
return (vector3int32) {vector.x / divider, vector.y / divider, vector.z / divider};
}
vector3int16 vector3Int32toInt16(vector3int32 vector) {
return (vector3int16) {vector.x, vector.y, vector.z};
}
int32_t intAbs(int32_t value) {
return value >= 0 ? value : -1 * value;
}
vector3int32 vector3int32Abs(vector3int32 one) {
return (vector3int32) {intAbs(one.x), intAbs(one.y), intAbs(one.z)};
}

12
modular.json Normal file
View File

@ -0,0 +1,12 @@
{
"dep": [
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}