C
C#2y 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
reflectronic2y ago
Vector3 Struct (System.Numerics)
Represents a vector with three single-precision floating-point values.
hanu
hanu2y ago
it seems good but is there a double-precision version of that?
reflectronic
reflectronic2y ago
no, not yet
hanu
hanu2y ago
hmm :(
reflectronic
reflectronic2y 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
reflectronic2y 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
hanu2y ago
it seems really cool is 'SIMD acceleration' what Vector<T> utilizes to optimize its performance?
reflectronic
reflectronic2y 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
hanu2y ago
got it
reflectronic
reflectronic2y 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
hanu2y ago
wow you're like a fountain of new knowledge thank you
Want results from more Discord servers?
Add your server
More Posts