{"id":14860859,"url":"https://github.com/ScalaMath/VecMatLib","last_synced_at":"2025-09-18T14:32:35.481Z","repository":{"id":65291217,"uuid":"584207811","full_name":"ScalaMath/VecMatLib","owner":"ScalaMath","description":"Open source Scala library that provides data structures for vectors and matrices","archived":false,"fork":false,"pushed_at":"2024-05-28T12:25:37.000Z","size":610,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-01T00:30:23.121Z","etag":null,"topics":["3d-graphics","algebra","functional-programming","java","linear-algebra","math","mathematics","maths","matrix-math","scala","vector-math"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScalaMath.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","contributing":null,"funding":".github/FUNDING.yml","license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["HexagonNico"],"ko_fi":"HexagonNico","custom":["https://paypal.me/hexagonnico"]}},"created_at":"2023-01-01T20:45:23.000Z","updated_at":"2025-05-07T14:41:14.000Z","dependencies_parsed_at":"2024-04-21T15:07:02.938Z","dependency_job_id":"ea3aa903-4dae-49f5-b652-bd4dbb75d45a","html_url":"https://github.com/ScalaMath/VecMatLib","commit_stats":null,"previous_names":["scalamath/vecmatlib"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/ScalaMath/VecMatLib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScalaMath%2FVecMatLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScalaMath%2FVecMatLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScalaMath%2FVecMatLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScalaMath%2FVecMatLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScalaMath","download_url":"https://codeload.github.com/ScalaMath/VecMatLib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScalaMath%2FVecMatLib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275781416,"owners_count":25527365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-18T02:00:09.552Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d-graphics","algebra","functional-programming","java","linear-algebra","math","mathematics","maths","matrix-math","scala","vector-math"],"created_at":"2024-09-19T20:01:08.072Z","updated_at":"2025-09-18T14:32:35.030Z","avatar_url":"https://github.com/ScalaMath.png","language":"Scala","readme":"\n# VecMatLib\n\nA Scala library for vectors and matrix math.\n\n## Project goals\n\nThe goal of VecMatLib is to provide easy-to-use and efficient linear algebra operations, needed by any 3D application.\n\nVectors and matrices structures are written in Scala to make the best use possible of Scala's operator overloading.\n\nVecMatLib was designed to be usable both in Scala and Java projects.\nAll methods with symbolic names have an alias for better interoperability with Java.\n\nAll operations in VecMatLib are designed to **not** modify the object on which the operation is invoked to respect the principles of purity and immutability of functional programming.\nEvery operation returns a new object.\n\n## Vector math\n\nVecMatLib offers 2-dimensional, 3-dimensional, and 4-dimensional vectors of type Int, Float, and Double with all their basic operations.\nAll operations do not modify the vector on which the operation is performed.\n\nScala example:\n```Scala\nvar a = Vec3f(1.0f, 1.5f, 1.0f)\nvar b = Vec3f(0.5f, 1.0f, 0.5f)\n\n// 'a' and 'b' will not change\nval c = a + b\n\n// Increase 'a' by 'b'\na = a + b // or a += b\n\n// Other operations\nval dotProduct = a dot b\nval normal = a.normalized\nval reflection = b.reflect(normal)\n```\n\nJava example:\n```Java\nVec3f a = new Vec3f(1.0f, 1.5f, 1.0f);\nVec3f b = new Vec3f(0.5f, 1.0f, 0.5f);\n\n// 'a' and 'b' will not change\nVec3f c = a.plus(b);\n\n// Increase 'a' by 'b'\na = a.plus(b);\n\n// Other operations\nfloat dotProduct = a.dot(b);\nVec3f normal = a.normalized();\nVec3f reflection = b.reflect(normal);\n```\n\n## Matrix math\n\nVecMatLib offers 2x2, 2x3, 3x3, 3x4, and 4x4 matrices of type Int, Float, and Double with all their basic operations as well as methods to build matrices out of basic transformations.\nAll operations do not modify the matrix on which the operation is performed.\n\nThe following example shows how a translation matrix is created and how the transformation is applied.\n\nScala example:\n```Scala\nvar position = Vec4f(x, y, z, 1.0f)\nval translation = Mat4f.translation(tx, ty, tz)\n\n// will result in (x + tx, y + ty, z + tz, 1.0f)\nposition = translation * position\n```\n\nJava example:\n```Java\nVec4f position = new Vec4f(x, y, z, 1.0f);\nMat4f translation = Mat4f.translation(tx, ty, tz);\n\n// will result in (x + tx, y + ty, z + tz, 1.0f)\nposition = translation.multiply(position);\n```\n\nMatrices can be multiplied together, allowing to create more complex transformations.\nThe same pattern can be used to create projection matrices and camera view matrices.\n\nScala example:\n```Scala\n// Create a 3x4 transformation matrix\nval transform = Mat3x4f.translation(tx, ty, tz) * Mat4f.rotation(rx, ry, rz) * Mat4f.scaling(sx, sy, sz)\nvar point = Vec3f(x, y, z)\n\n// Applies first a scaling by (sx, sy, sz),\n// then a rotation by (rx, ry, rz) in radians,\n// then a translation by (tx, ty, tz)\npoint = transform * (point, 1.0f)\n```\n\nJava example:\n```Java\n// Create a 3x4 transformation matrix\nMat3x4f transform = Mat3x4f.translation(tx, ty, tz)\n        .multiply(Mat4f.rotation(rx, ry, rz))\n        .multiply(Mat4f.scaling(sx, sy, sz));\nVec3f point = new Vec3f(x, y, z);\n\n// Applies first a scaling by (sx, sy, sz),\n// then a rotation by (rx, ry, rz) in radians,\n// then a translation by (tx, ty, tz)\npoint = transform.multiply(point, 1.0f);\n```\n\n## Quaternions\n\nVecMatLib provides a `Quatf` and a `Quatd` class for single-precision and double-precision quaternions respectively.\nOperations concerning quaternions follow the same principles as the ones concerning vectors and matrices.\n\n```Scala\nval q1 = Quatd(0.7071068, 0.0, 0.7071068, 0.0)\nval q1 = Quatd(0.7071068, 0.0, 0.0, 0.7071068)\nval composed = q1 * q2\n```\n\nUnit quaternions can be used to represent rotations.\n\n```Scala\nval quaternion = Quatd(Vec3d.Up, math.Pi / 2.0) // Represents a rotation of 90 degrees around the y axis\nvar point = Vec3d(1.0, 0.0, 0.0)\npoint = quaternion.rotate(point) // Results in Vec3d(0.0, 0.0, -1.0)\n```\n\nRotations can also be specified in terms of euler angles.\nThe default rotation order is `ZYX`.\nOther rotation orders can be specified with the `EulerOrder` enum.\n\n```Scala\nval euler = Vec3d(math.Pi * 0.5, 0.0, math.Pi * 0.5)\nval quaternion = Quatd.fromEuler(euler, EulerOrder.XYZ)\nval matrix = Mat3d.rotation(quaternion)\n```\n\n## Complex numbers\n\nAn additional library for complex numbers is [CmplxLib](https://github.com/ScalaMath/CmplxLib).\n\nCmplxLib depends on VecMatLib and provides complex numbers, as well as complex vectors and complex matrices.\n\n## Color math\n\nColors can be seen as 3D or 4D vectors, whose components are the red, green, blue, and alpha components of the color.\n\nA library for color math that depends on VecMatLib is [ColorLib](https://github.com/ScalaMath/ColorLib).\n\n## Using with LWJGL\n\nVecMatLib can be used together with [LWJGL](https://lwjgl.org) to build transformation matrices and set uniform variables in shaders.\n\nThis example first creates a 3D float vector, then loads the value into the active shader program.\n\n```Java\nVec3f lightPosition = new Vec3f(-3.0f, 10.0f, 6.0f);\nint location = GL20.glGetUniformLocation(program, \"light_position\");\nGL20.glUniform3f(location, lightPosition.x(), lightPosition.y(), lightPosition.z());\n```\n\nMatrices can be loaded into shaders by converting them into float buffers by using the `BufferUtils` class provided by LWJGL.\n\n```Java\nMat3f matrix = ...\nFloatBuffer buffer = BufferUtils.createFloatBuffer(9);\nbuffer.put(matrix.m00()); buffer.put(matrix.m01()); buffer.put(matrix.m02());\nbuffer.put(matrix.m10()); buffer.put(matrix.m11()); buffer.put(matrix.m12());\nbuffer.put(matrix.m20()); buffer.put(matrix.m21()); buffer.put(matrix.m22());\nGL20.glUniformMatrix3fv(location, true, buffer.flip());\n```\n\nNote that matrices in OpenGL uses column-major matrix order, therefore the matrix must be transposed by passing `true` to the OpenGL method when it is loaded.\n\nThe `Mat4f` and `Mat4d` classes also contain methods to create orthographic or perspective projection matrices.\n\n```Java\n// 70 degrees fov, 16/9 aspect ratio, 0.1 near plane distance, 1000 far plane distance\nMat4f projection = Mat4f.perspectiveProjection(Math.toRadians(70.0f), 16.0f / 9.0f, 0.1f, 1000.0f);\nFloatBuffer buffer = BufferUtils.createFloatBuffer(16);\nbuffer.put(matrix.m00()); buffer.put(matrix.m01()); buffer.put(matrix.m02()); buffer.put(matrix.m03());\nbuffer.put(matrix.m10()); buffer.put(matrix.m11()); buffer.put(matrix.m12()); buffer.put(matrix.m13());\nbuffer.put(matrix.m20()); buffer.put(matrix.m21()); buffer.put(matrix.m22()); buffer.put(matrix.m23());\nbuffer.put(matrix.m30()); buffer.put(matrix.m31()); buffer.put(matrix.m32()); buffer.put(matrix.m33());\nGL20.glUniformMatrix4fv(location, true, buffer.flip());\n```\n\n## Multithreading\n\nDue to VecMatLib not using any internal or temporal objects during any computations, neither modifying objects on which operations are called, it can be used safely in a multithreaded application.\n\n## Add VecMatLib to your project\n\n### sbt\n\n```sbt\nlibraryDependencies += \"io.github.scalamath\" % \"vecmatlib\" % \"3.1\"\n```\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.scalamath\u003c/groupId\u003e\n    \u003cartifactId\u003evecmatlib\u003c/artifactId\u003e\n    \u003cversion\u003e3.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n\n```groovy\nimplementation 'io.github.scalamath:vecmatlib:3.1'\n```\n\n## Questions and answers\n\n**Q**: Why does VecMatLib not use scala 3?\n\n**A**: One of the design goals of VecMatLib is to be usable both in Scala and Java. Support for Scala 3 in IDEs is still actively being developed, therefore a Scala 3 library may not be suitable to work with.\n\n## Contributing\n\nVecMatLib was developed by a single person.\nInitially a university project, later completed and turned into a fully usable library.\n\nYour contributions are always welcome!\nPlease submit a pull request or open an issue if you want to contribute with bug fixes, code improvements, documentation, and better unit test coverage.\n\n## Support\n\nSupport the project with a donation:\n\n* [PayPal](https://paypal.me/hexagonnico)\n* [Ko-fi](https://ko-fi.com/HexagonNico)","funding_links":["https://github.com/sponsors/HexagonNico","https://ko-fi.com/HexagonNico","https://paypal.me/hexagonnico"],"categories":["Table of Contents"],"sub_categories":["Science and Data Analysis"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScalaMath%2FVecMatLib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FScalaMath%2FVecMatLib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScalaMath%2FVecMatLib/lists"}