{"id":15038922,"url":"https://github.com/djben/mathutil","last_synced_at":"2025-04-10T00:02:20.216Z","repository":{"id":64059978,"uuid":"97915719","full_name":"DJBen/MathUtil","owner":"DJBen","description":"Collection of matrix arithmetics, CoreGraphics and SceneKit operator overloading and various interpolation support.","archived":false,"fork":false,"pushed_at":"2017-12-29T23:46:38.000Z","size":56,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-10T00:01:17.685Z","etag":null,"topics":["carthage","euler-angles","interpolation","mathematics","matrix","quaternion","swift","swift4","vector-math"],"latest_commit_sha":null,"homepage":null,"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/DJBen.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":"2017-07-21T06:48:18.000Z","updated_at":"2020-12-11T15:58:16.000Z","dependencies_parsed_at":"2023-01-14T20:31:08.237Z","dependency_job_id":null,"html_url":"https://github.com/DJBen/MathUtil","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJBen%2FMathUtil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJBen%2FMathUtil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJBen%2FMathUtil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DJBen%2FMathUtil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DJBen","download_url":"https://codeload.github.com/DJBen/MathUtil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131322,"owners_count":21052819,"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","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":["carthage","euler-angles","interpolation","mathematics","matrix","quaternion","swift","swift4","vector-math"],"created_at":"2024-09-24T20:40:46.881Z","updated_at":"2025-04-10T00:02:20.151Z","avatar_url":"https://github.com/DJBen.png","language":"Swift","readme":"# MathUtil\n\n[![Language](https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat)](https://swift.org)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Build Status](https://travis-ci.org/DJBen/MathUtil.svg?branch=master)](https://travis-ci.org/DJBen/MathUtil)\n\n## Overview\n\n- Strongly typed radian, degree and hour angle classes and conversions.\n- 3x3 matrix, 4x4 matrix and quaternion support.\n  - Conversion between matrix, quaternion, Euler angle, and axis and rotation.\n  - Matrix, quaternion multiplication, inversion and scalar multiplication.\n  - Overloaded multiplication and division operators in contexts of matrix and quaternion.\n- Interpolation support for linear, quadratic and cubic curves with ease-in, ease-out, ease-in-out modes.\n- Detect whether two line segments cross each other.\n- Operator overloading for `SCNVector3` and more.\n\n## Installation\n\n### Carthage\n\n    # Swift 4.0\n    github \"DJBen/MathUtil\" ~\u003e 0.3.0\n\nThis version is compatible with Swift 4. To use Swift 3.x compatible version, use `0.1.x` instead.\n\n    # Swift 3.x\n    github \"DJBen/MathUtil\" ~\u003e 0.1.0\n\n\n## Usage\n\n### Strongly Typed Angles\n#### Radian-degree Angle Conversion\n```swift\nRadianAngle(degreeAngle: DegreeAngle(30)).value // 0.523...\nDegreeAngle(radianAngle: RadianAngle(Double.Pi / 2)).value  // 90\n```\n#### Hour Angle Conversion and Formatting\n```swift\n// Sirius' right ascension is 6h 45m 9s\nlet deg = DegreeAngle(hour: 6, minute: 45, second: 9)\ndeg.value // 101.2875\n\nlet hourAngle = HourAngle(value: deg)\n// Use any custom number formatters for different decimal lengths\nhourAngle.compoundDecimalNumberFormatter = NumberFormatter()\nprint(hourAngle.compoundDescription) // 6h 45m 9s\n\n// Antares' right ascension is −26.432002 degrees\nlet degreeAngle = DegreeAngle(-26.432002)\nprint(degreeAngle.compoundDescription) // -26° 25′ 55″\n```\n\n### Matrix, Quaternion and Vector Arithmetics\n\nSee documentation for [VectorMath](https://github.com/nicklockwood/VectorMath).\n\n### Interpolations\n\n#### Linear interpolation\n```swift\n// Starts at 2.1; ends at 7.5; wants to know 85% value.\nlet interp = Easing(startValue: 2.1, endValue: 7.5)\ninterp.value(at: 0.85)   // 6.69\n```\n#### Quadratic, Cubic, Ease In, Ease Out\n\nThe following easing functions are available and [here](http://gizma.com/easing/) is their mathematic definitions.\n```swift\npublic enum EasingFunction {\n    case linear\n    case quadraticEaseIn\n    case quadraticEaseOut\n    case quadraticEaseInOut\n    case cubicEaseIn\n    case cubicEaseOut\n    case cubicEaseInOut\n}\n```\nJust pass in the function when initializing `Easing` and take advantage of it!\n```swift\nEasing(easingMethod: .cubicEaseInOut, startValue: 21, endValue: -9)\n```\n### Operator overloading\n\n- Add operator arithmetics for `CGVector` and `SCNVector3`.\n\n## Remarks\n\n`MathUtil/VectorMath**` are based on\n[@nicklockwood](https://github.com/nicklockwood)'s [VectorMath](https://github.com/nicklockwood/VectorMath). Great thanks!\n  - Based on 0.3 version. Not bumping up to the latest release because I adopted a different order of deriving Euler angles from Quaternion and vice versa.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjben%2Fmathutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjben%2Fmathutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjben%2Fmathutil/lists"}