{"id":16000596,"url":"https://github.com/jedwards1211/ritter-bounding-sphere","last_synced_at":"2025-09-28T13:30:49.701Z","repository":{"id":34648462,"uuid":"182016689","full_name":"jedwards1211/ritter-bounding-sphere","owner":"jedwards1211","description":"Compute bounding sphere for a set of points using Jack Ritter's algorithm","archived":false,"fork":false,"pushed_at":"2023-01-03T19:54:52.000Z","size":3905,"stargazers_count":3,"open_issues_count":24,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-28T19:45:12.594Z","etag":null,"topics":["3d","bounding-sphere","geometry","point-cloud","spatial","spatial-indexing","sphere"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/jedwards1211.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-18T04:35:50.000Z","updated_at":"2023-05-19T01:58:42.000Z","dependencies_parsed_at":"2023-01-15T08:30:57.152Z","dependency_job_id":null,"html_url":"https://github.com/jedwards1211/ritter-bounding-sphere","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fritter-bounding-sphere","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fritter-bounding-sphere/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fritter-bounding-sphere/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedwards1211%2Fritter-bounding-sphere/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jedwards1211","download_url":"https://codeload.github.com/jedwards1211/ritter-bounding-sphere/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234518758,"owners_count":18845822,"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":["3d","bounding-sphere","geometry","point-cloud","spatial","spatial-indexing","sphere"],"created_at":"2024-10-08T09:04:56.744Z","updated_at":"2025-09-28T13:30:44.385Z","avatar_url":"https://github.com/jedwards1211.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ritter-bounding-sphere\n\n[![CircleCI](https://circleci.com/gh/jedwards1211/ritter-bounding-sphere.svg?style=svg)](https://circleci.com/gh/jedwards1211/ritter-bounding-sphere)\n[![Coverage Status](https://codecov.io/gh/jedwards1211/ritter-bounding-sphere/branch/master/graph/badge.svg)](https://codecov.io/gh/jedwards1211/ritter-bounding-sphere)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/ritter-bounding-sphere.svg)](https://badge.fury.io/js/ritter-bounding-sphere)\n\nCompute bounding sphere for a set of points using Jack Ritter's algorithm\n\nhttps://en.wikipedia.org/wiki/Bounding_sphere#Ritter's_bounding_sphere\n\nRitter's algorithm is very simple and efficient, but gives only a coarse result\nwhich is usually 5% to 20% larger than the optimum.\n\n## Compatibility\n\n`ritter-bounding-sphere` requires `Symbol.iterator` to be supported.\nIt definitely works in Node 8+, but older environments may require a polyfill.\n\n## `require('ritter-bounding-sphere')(points, [output])`\n\nComputes a bounding sphere for `points`, which must be an\n`Iterable\u003c[x, y, z]\u003e`. The iterator can mutate and yield the\nsame array instance more than once if desired.\n\nReturns the bounding sphere as an array of the form `[x, y, z, radiusSquared]`\nwhere `x, y, z` is the center. You can pass the `output` array to store the\nresult in if you want to avoid the array allocation.\n\n## Adapting other point formats\n\n`ritter-bounding-sphere` accepts point data in arrays so that you can optionally\nuse `Float32Array`/`Float64Array`s for speed. But if your points are in a\ndifferent format you can easily adapt them to this library.\n\nLet's say your points are in `{x: number, y: number, z: number}` format instead,\nand you want to output a bounding sphere of the form\n`{center: {x: number, y: number, z: number}, radius: number}`.\nHere's how your adapter could work:\n\n```js\nconst boundingSphere = require('ritter-bounding-sphere')\n\nexport function myBoundingSphere(points) {\n  const point = [0, 0, 0]\n  function* adapter() {\n    for (let { x, y, z } of points) {\n      point[0] = x\n      point[1] = y\n      point[2] = z\n      yield point\n    }\n  }\n  const [x, y, z, r2] = boundingSphere(adapter())\n  return {\n    center: { x, y, z },\n    radius: Math.sqrt(r2),\n  }\n}\n```\n\n## Example\n\nOn a tetrahedron:\n\n```\n\u003e require('ritter-bounding-sphere')([[0, 0, 0], [1, 1, 0], [1, 0, 1], [0, 1, 1]])\n[ 0.5540595619320077,  // center x\n  0.44594043806799233, // center y\n  0.2785205487644272,  // center z\n  1.1344965948917598 ] // radius squared\n```\n\nNotice that this is about 22% larger than the optimum bounding sphere\n([0.5, 0.5, 0.5, 0.75]). A perfect tetrahedron is one of the worst cases\nsince all its points are equidistant.\n\n## Loose mode\n\n`require('ritter-bounding-sphere')` corrects for floating-point error by\ndoing a final pass to check if all points are in the resulting sphere,\nincreasing the radius squared as necessary.\nIf you want more performance and less accuracy, you can skip this final pass by\nusing `require('ritter-bounding-sphere').loose` instead, which has the same\nsignature.\n\nSome points may lie just barely outside the loose output sphere (for instance,\non 100 random points between `[0, 0, 0]` and `[1, 1, 1]`) the output sphere's\nradius squared is usually ~`1e-16` less than the distance squared to some point.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedwards1211%2Fritter-bounding-sphere","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjedwards1211%2Fritter-bounding-sphere","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedwards1211%2Fritter-bounding-sphere/lists"}