{"id":1387,"url":"https://github.com/m4tbat/SwiftMath","last_synced_at":"2025-08-02T04:31:03.870Z","repository":{"id":32984063,"uuid":"36610047","full_name":"m4tbat/SwiftMath","owner":"m4tbat","description":":triangular_ruler: A math framework for Swift. Includes: vectors, matrices, complex numbers, quaternions and polynomials.","archived":true,"fork":false,"pushed_at":"2019-05-03T13:05:37.000Z","size":822,"stargazers_count":177,"open_issues_count":2,"forks_count":15,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-05-29T04:48:15.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m4tbat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-31T15:46:24.000Z","updated_at":"2023-11-06T07:05:12.000Z","dependencies_parsed_at":"2022-07-11T00:30:28.334Z","dependency_job_id":null,"html_url":"https://github.com/m4tbat/SwiftMath","commit_stats":null,"previous_names":["madbat/swiftmath"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/m4tbat/SwiftMath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4tbat%2FSwiftMath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4tbat%2FSwiftMath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4tbat%2FSwiftMath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4tbat%2FSwiftMath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m4tbat","download_url":"https://codeload.github.com/m4tbat/SwiftMath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m4tbat%2FSwiftMath/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334610,"owners_count":24233793,"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-08-02T02:00:12.353Z","response_time":74,"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":[],"created_at":"2024-01-05T20:15:45.280Z","updated_at":"2025-08-02T04:31:03.534Z","avatar_url":"https://github.com/m4tbat.png","language":"Swift","funding_links":[],"categories":["Math"],"sub_categories":["Other Hardware"],"readme":"# SwiftMath\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nSwiftMath is a Swift framework providing some useful math constructs and functions, like complex numbers, vectors, matrices, quaternions, and polynomials.\n\n:warning: *SwiftMath is work in progress, in alpha state. Master is currently targeting Swift 2.1.*\n\n## Requirements\n\nSwiftMath requires iOS 8.0+ / OS X 10.9+.\n\n## Installation\n\nSwiftMath can be installed with the dependency manager [Carthage](https://github.com/Carthage/Carthage).\n*\tAdd the following line to your project's Cartfile\n```\ngithub \"madbat/SwiftMath\"\n```\n*\tIn the terminal, run `carthage update`\n*\tLink your project target(s) with the built frameworks. Application targets should also ensure that the framework gets copied into their application bundle.\n\n## Usage\n\n### Vector3\n\nVector3 — as the name suggests — represents a vector in the three-dimensional Euclidean space (aka R×R×R).\nSome of the most common uses of 3D vectors consist in encoding physical quantities like position, velocity, acceleration, force, and many others.\n\n```swift\nlet v1 = Vector3(x: 1, y: 2, z: 3)\nlet v2 = Vector3(x: 5, y: 6, z: 7)\n\n// vector sum\nlet v3 = v1 + v2 // Vector3(x: 6, y: 8, z: 10)\n\n// length\nv3.length // equals v3.norm\n\n// zero vector\nVector3.zero() // Vector3(x: 0, y: 0, z: 0)\n\n// unit-length vector\nv3.unit() // divides v3 by its length\n```\n\n### Vector2\n\nPretty much like `Vector3`, but for 2D vectors.\n\n### Complex\n\nComplex numbers extend real numbers in order to solve problems that cannot be solved with real numbers alone.\nFor example, the roots of a polynomial equation of degree \u003e 1 can always be expressed with complex numbers, but not with real numbers.\n\n```swift\n// the default constructor for Complex takes the real and imaginary parts as parameters\nlet c1 = Complex(1.0, 3.0)\nc1.re // 1.0\nc1.im // 3.0\n\n// a complex can also be constructed by using the property i defined on Float and Double\nlet c2 = 5 + 1.i // Complex(5.0, 1.0)\n\n// complex conjugate\nc2.conj() // Complex(5.0, -1.0)\n\n// polar form\nlet c3 = Complex(abs: 2.0, arg: -4.0)\n\nlet realComplex = Complex(10.0, 0.0)\nrealComplex.isReal // true\n```\n\n### Quaternion\n\nQuaternions extend complex numbers to 4 dimensions.\nThey're handy to rotate three-dimensional vectors.\n\n```swift\n// rotating a vector by π/2 around its x axis\nlet original = Vector3(x: 3, y: 4, z: 0)\nlet rotation = Quaternion(axis: Vector3(x: 1, y: 0, z: 0), angle: Double.PI/2.0)\nlet rotated = original.rotate(rotation) // Vector3(x: 3, y: 0, z: 4.0)\n```\n\n### Polynomial\n\nPolynomial lets you represent – and find the roots of – a polynomial expression.\n\nThe following snippet shows how to express the polynomial `x^2 + 4x + 8`\n```swift\nlet p = Polynomial(1, 4, 8)\n```\n\nUse Polynomial's `roots()` method to calculate its roots, represented as a (multi)set of complex numbers:\n```swift\np.roots() // returns { (-2 - 2i), (-2 + 2i) }\n```\nFor polynomials of degree \u003c= 4, `roots()` defaults to using the analytic method, while for polynomials of higher degrees it uses the the [Durand-Kerner method](http://en.wikipedia.org/wiki/Durand%E2%80%93Kerner_method).\nIt is possible to force the root finding process to use the numeric method also for polynomials\nof degree \u003c= 4, using `roots(preferClosedFormSolution: false)`.\n\n## Contributing\n\nContributions in any form (especially pull requests) are _very_ welcome!\n\n## License\n\nSwiftMath is released under the MIT License. See the [LICENSE](https://github.com/madbat/SwiftMath/blob/master/LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4tbat%2FSwiftMath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm4tbat%2FSwiftMath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm4tbat%2FSwiftMath/lists"}