{"id":16379888,"url":"https://github.com/iprodigy/physics","last_synced_at":"2025-02-21T14:33:09.681Z","repository":{"id":90325925,"uuid":"67556014","full_name":"iProdigy/Physics","owner":"iProdigy","description":"Java library for Newtonian Mechanics Modeling with a focus on Immutable Fluency","archived":false,"fork":false,"pushed_at":"2018-09-05T14:00:18.000Z","size":57,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-19T22:39:39.083Z","etag":null,"topics":["angle","cartesian","euclidean","fluent-api","immutable","java","linear-algebra","math","mechanics","physics","scalar","scalar-quantity","simulation","vector","vector-calculation","vector-computations","vector-math"],"latest_commit_sha":null,"homepage":"","language":"Java","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/iProdigy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-07T00:05:15.000Z","updated_at":"2021-10-11T06:36:42.000Z","dependencies_parsed_at":"2023-03-04T09:00:32.795Z","dependency_job_id":null,"html_url":"https://github.com/iProdigy/Physics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iProdigy%2FPhysics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iProdigy%2FPhysics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iProdigy%2FPhysics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iProdigy%2FPhysics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iProdigy","download_url":"https://codeload.github.com/iProdigy/Physics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240031825,"owners_count":19737023,"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":["angle","cartesian","euclidean","fluent-api","immutable","java","linear-algebra","math","mechanics","physics","scalar","scalar-quantity","simulation","vector","vector-calculation","vector-computations","vector-math"],"created_at":"2024-10-11T03:49:52.661Z","updated_at":"2025-02-21T14:33:09.619Z","avatar_url":"https://github.com/iProdigy.png","language":"Java","readme":"# Classical Mechanics\nComputation and Modeling of Newtonian Physics in Java 8 with Functionality and Null-Safety in mind.\n## Immutable, Functional Scalars\nFloating-point quantities without direction.\n```java\nScalar s = () -\u003e 5.0;\ns.getMagnitude(); // 5.0\n```\n### Computation\nScalars have basic arithmetic functions already built in that are [pure](https://en.wikipedia.org/wiki/Pure_function).\n```java\nScalar s1 = () -\u003e 12.0;\nScalar s2 = () -\u003e 5.0;\n\nScalar add = s1.add(s2) // Magnitude: 17\nScalar sub = s1.subtract(s2); // Magnitude: 7\n\nScalar mul = s1.multiply(s2); // Magnitude: 60\nScalar mul2 = s1.multiply(10.0); // Magnitude: 120\n\nScalar div = s1.divide(s2); // Magnitude: 12.0 / 7.0 ≈ 1.7143\nScalar div2 = s1.divide(10.0); // Magnitude: 1.2\n\ns1.getMagnitude(); // Still 12\ns2.getMagnitude(); // Still 5\n```\n### Immutable Angles\nA scalar quantity that inherits the above properties.\n\nSupports\n* Standard Units (Degrees, Radians, Gradians, Turns)\n* Conversions between Units\n* Quadrant determination\n* Trigonometric Functions\n\n```java\n// Instantiation\nAngle a = new Angle(30, AngleUnit.DEGREES);\nAngle b = new Angle(5 * Math.PI / 6, AngleUnit.RADIANS);\n\na.getQuadrant(); // I\nb.getQuadrant(); // II\n\na.sin(); // 0.5\na.cos(); // ~0.866\na.tan(); // ~0.577\n\na.csc(); // 2.0\na.sec(); // ~1.1547\na.cot(); // ~1.732\n\nAngle add = a.add(b); // 180°\nAngle sub = b.subtract(a); // 2π/3 rad\nAngle mul = a.multiply(2.0); // 60°\n\n// Conversions\nAngle aGrads = a.convert(AngleUnit.GRADIANS);\ndouble turns = a.getTurns();\n\n// Comparisons\nboolean smaller = a.compareTo(b) \u003c 0; // true\n```\nNote that these functions are pure in that they do not mutate the angle but rather return a new values.\n## Immutable Vectors\nQuantities with magnitude and direction. \n```java\n// Empty Vector Initialization\nVector a = new Vector();\n\n// Can initialize Vectors with their magnitude and angle\nVector b = new Vector(5.0, 25.0, AngleUnit.DEGREES);\nVector c = new Vector(5.0, new Angle(Math.PI, AngleUnit.RADIANS));\n\n// Can initialize Vectors with their components\nVector d = new Vector(1.0, 2.0);\nVector e = new Vector(1.0, 2.0, 3.0);\n\n// Can initialize Vectors with double arrays or lists\nVector f = new Vector(Arrays.asList(4.0, 5.0, 6.0));\nVector g = new Vector(new double[] {7.0, 8.0, 9.0});\n```\n### Computation\n#### Componentization\n```java\nList\u003cDouble\u003e aComps = a.getComponents(); // []\nList\u003cDouble\u003e bComps = b.getComponents(); // [4.5315, 2.1131]\n```\nNote that these Lists are actually instances of UnmodifiableList so that Vectors are immutable.\n#### Addition / Subtraction\n```java\nVector add = b.add(c);\nVector sub = c.subtract(d);\n```\n#### Multiplication / Division\n```java\nVector mul = e.multiply(2.0);\nVector mul2 = f.multiply(() -\u003e 10.0);\n\nVector div = f.divide(2.0);\nVector div2 = f.divide(() -\u003e 10.0);\n\ndouble dot = f.dotProduct(g);\nVector cross = f.crossProduct3D(g);\n```\n#### Angular Difference\n```java\nAngle angDiff = f.angularDiff(g);\ndouble degDiff = f.degreeDiff(g);\n```\n#### Linear Interpolation\n```java\nVector lerp = f.interpolate(g, 0.50);\n```\n#### Normalization\n```java\n// Creates a unit vector with the same direction\nVector unit = g.normalized();\n```\n#### Comparison\n```java\nboolean larger = g.compareTo(f) \u003e 0; // true\n```\nNote that these functions are pure in that they do not mutate the vector but rather return a new values.\n## Chaining Calls\nThese immutable values also provide a fluent interface for method chaining.\n```java\nAngle a = new Angle(1125, AngleUnit.DEGREES)\n        .simplified()\n        .subtract(new Angle(15, AngleUnit.DEGREES))\n        .multiply(2.0);\n\n// a → 60°\n```\n```java\nVector v = new Vector(2.5, 5.0, 7.5)\n        .add(new Vector(4.5, 6.0, 2.5))\n        .divide(5.0)\n        .crossProduct3D(new Vector(1.0, 2.0, 3.0));\n\n// v → components=[2.6, -2.2, 0.6], magnitude=3.4583, angle=41.253°\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiprodigy%2Fphysics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiprodigy%2Fphysics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiprodigy%2Fphysics/lists"}