{"id":25060046,"url":"https://github.com/stla/mpolynom","last_synced_at":"2026-04-30T01:38:01.220Z","repository":{"id":73101564,"uuid":"158342724","full_name":"stla/mpolynom","owner":"stla","description":"An R package for differentiating and evaluating multivariate polynoms.","archived":false,"fork":false,"pushed_at":"2018-11-22T13:09:46.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-31T11:15:20.256Z","etag":null,"topics":["c-plus-plus","polynomials","r"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-11-20T06:39:49.000Z","updated_at":"2019-04-19T13:22:32.000Z","dependencies_parsed_at":"2023-03-17T20:30:48.860Z","dependency_job_id":null,"html_url":"https://github.com/stla/mpolynom","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/stla/mpolynom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fmpolynom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fmpolynom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fmpolynom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fmpolynom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stla","download_url":"https://codeload.github.com/stla/mpolynom/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stla%2Fmpolynom/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32451478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["c-plus-plus","polynomials","r"],"created_at":"2025-02-06T15:56:32.539Z","updated_at":"2026-04-30T01:38:01.200Z","avatar_url":"https://github.com/stla.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mpolynom\n\nTo get the normals of an implicit surface, one needs the gradient of the \nimplicit equation. Many known implicit surfaces are algebraic: the implicit \nequation is defined by a multivariate polynomial.\n\nInstead of entering the gradient manually, I was looking for a way to derive it \nwith R in the case of an algebraic surface. I have been able to do so with the \n`multipol` package. Unfortunately, the evaluation of a multivariate polynomial \nwith the `multipol` package (function `as.function`) is very slow.\n\nThis is why I created the `mpolynom` package. It depends on `multipol`, and it \nenhances it by providing a fast evaluation of a multivariate polynom. \nThis package is built on a C++ library written by John Burkardt, which is ported \nto R with the help of the `Rcpp` package.\n\n```r\n# define a polynomial function ####\nphi \u003c- (1+sqrt(5))/2\nf0 \u003c- function(x,y,z){\n  4*(phi^2*x^2-y^2)*(phi^2*y^2-z^2)*(phi^2*z^2-x^2) - \n    (1+2*phi)*(x^2+y^2+z^2-1)^2*1\n}\nf \u003c- function(x,y,z){\n  ifelse(x*x+y*y+z*z \u003c 3, f0(x,y,z), NaN)\n}\nlibrary(mpolynom)\nP \u003c- f0(x., y., z.)\n\n# run the marching cubes algorithm ####\nnx \u003c- 120; ny \u003c- 120; nz \u003c- 120\nx \u003c- seq(-1.8, 1.8, length=nx) \ny \u003c- seq(-1.8, 1.8, length=ny)\nz \u003c- seq(-1.8, 1.8, length=nz) \ng \u003c- expand.grid(x=x, y=y, z=z)\nvoxel \u003c- array(with(g, f(x,y,z)), c(nx,ny,nz))\nlibrary(misc3d)\nsurf \u003c- computeContour3d(voxel, maxvol=max(voxel[!is.nan(voxel)]), level=0, \n                         x=x, y=y, z=z)\n\n# build the rgl mesh ####\nfx \u003c- differentiate(P, c(1,0,0))\nfy \u003c- differentiate(P, c(0,1,0))\nfz \u003c- differentiate(P, c(0,0,1))\ngradient \u003c- function(xyz){\n  cbind(evalPoly(fx,xyz), evalPoly(fy,xyz), evalPoly(fz,xyz))\n}\nlibrary(rgl)\nmesh \u003c- tmesh3d(vertices = t(surf),\n                indices = matrix(1:nrow(surf), nrow=3),\n                homogeneous = FALSE,\n                normals = -gradient(surf))\nmesh$normals \u003c- rbind(mesh$normals,1)\n\n# plot ####\nopen3d(windowRect = c(50, 50, 550, 550))\nbg3d(rgb(54, 57, 64, maxColorValue = 255))\nshade3d(mesh, color=rgb(1,0,1))\n```\n\n[![](https://thumbs.gfycat.com/GraciousRevolvingFlatfish-size_restricted.gif)](https://gfycat.com/GraciousRevolvingFlatfish)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fmpolynom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstla%2Fmpolynom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstla%2Fmpolynom/lists"}