C
C#3y ago
hanu

Most convenient method to handle 3D vectors?

I'm looking for a struct/class in which magnitude(L2 norm), normalize, multiplication with a scalar, and dot product are implemented. Thank you.
11 Replies
reflectronic
reflectronic3y ago
Vector3 Struct (System.Numerics)
Represents a vector with three single-precision floating-point values.
hanu
hanuOP3y ago
it seems good but is there a double-precision version of that?
reflectronic
reflectronic3y ago
no, not yet
hanu
hanuOP3y ago
hmm :(
reflectronic
reflectronic3y ago
for something like that i would suggest using a library like https://www.nuget.org/packages/Silk.NET.Maths/
Silk.NET.Maths 2.16.0
Silk.NET is a high-speed, advanced library, providing bindings to popular low-level APIs such as OpenGL, OpenCL, OpenAL, OpenXR, GLFW, SDL, Vulkan, Assimp, and DirectX.
reflectronic
reflectronic3y ago
it has a Vector3<T> that very closely mirrors the one in System.Numerics it is not SIMD accelerated like S.N.V, but i used it to run a numerical simulation and it at least functioned correctly
hanu
hanuOP3y ago
it seems really cool is 'SIMD acceleration' what Vector<T> utilizes to optimize its performance?
reflectronic
reflectronic3y ago
yeah. Vector<T> is the most "conventional" SIMD-like type in System.Numerics--it's not a euclidean vector, or really similar to any mathematical object, it's just a thing that lets you do arithmetic on n values at once
hanu
hanuOP3y ago
got it
reflectronic
reflectronic3y ago
Vector2/3/4 have special support in the runtime for register allocation (they use the special hardware vector registers) and many of their operations (e.g. adding vectors can be done with SIMD, since it's just componentwise additions, like Vector<T>), but the hardware doesn't intrinsically support all of the mathematical operations (some can naturally be implemented in terms of others but aren't at the moment. stuff like Cross and the Transform ones in particular, maybe there are a handful of others)
hanu
hanuOP3y ago
wow you're like a fountain of new knowledge thank you

Did you find this page helpful?