All Projects → yszhao91 → Cga.js

yszhao91 / Cga.js

Licence: mit
CGA 3D 计算几何算法库 | 3D Compute Geometry Algorithm Library webgl three.js babylon.js等任何库都可以使用

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
js
455 projects
ts
41 projects

Projects that are alternatives of or similar to Cga.js

Shadoweditor
Cross-platform 3D scene editor based on three.js, golang and mongodb for desktop and web. https://tengge1.github.io/ShadowEditor-examples/
Stars: ✭ 1,060 (+238.66%)
Mutual labels:  webgl, threejs, gis
Three Mesh Bvh
A BVH implementation to speed up raycasting against three.js meshes.
Stars: ✭ 302 (-3.51%)
Mutual labels:  graphics, threejs, geometry
Cesium
An open-source JavaScript library for world-class 3D globes and maps 🌎
Stars: ✭ 8,095 (+2486.26%)
Mutual labels:  webgl, gis, geospatial
L7
🌎 Large-scale WebGL-powered Geospatial Data Visualization analysis framework which relies on Mapbox GL or AMap to render basemaps.
Stars: ✭ 2,517 (+704.15%)
Mutual labels:  webgl, gis, geospatial
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (+38.66%)
Mutual labels:  graphics, webgl, threejs
Wechart
Create all the [ch]arts by cax or three.js - Cax 和 three.js 创造一切图[表]
Stars: ✭ 152 (-51.44%)
Mutual labels:  graphics, webgl, threejs
Threejs Sandbox
Set of experiments and extensions to THREE.js.
Stars: ✭ 163 (-47.92%)
Mutual labels:  webgl, threejs, geometry
Openglobus
JavaScript 3d maps and geospatial data visualization engine library.
Stars: ✭ 199 (-36.42%)
Mutual labels:  webgl, gis, geospatial
3dtilesrendererjs
Renderer for 3D Tiles in Javascript using three.js
Stars: ✭ 333 (+6.39%)
Mutual labels:  graphics, threejs, geometry
Lume
Create CSS3D/WebGL applications declaratively with HTML. Give regular DOM elements shadow and lighting.
Stars: ✭ 445 (+42.17%)
Mutual labels:  graphics, webgl, threejs
topo
A Geometry library for Elixir that calculates spatial relationships between two geometries
Stars: ✭ 125 (-60.06%)
Mutual labels:  geometry, geospatial, gis
geowarp
Super Low-Level Raster Reprojection and Resampling Library
Stars: ✭ 20 (-93.61%)
Mutual labels:  geospatial, gis
3dio Js
JavaScript toolkit for interior apps
Stars: ✭ 255 (-18.53%)
Mutual labels:  webgl, threejs
React Three Editable
👀 ✏️ Edit your react-three-fiber scene with a visual editor without giving up control over your code.
Stars: ✭ 261 (-16.61%)
Mutual labels:  webgl, threejs
Ofelia
A real-time cross-platform creative coding tool for multimedia development
Stars: ✭ 269 (-14.06%)
Mutual labels:  graphics, webgl
THREEg.js
three.js addon to create special or extended geometries. The addon generates indexed or non indexed BufferGeometries.
Stars: ✭ 33 (-89.46%)
Mutual labels:  threejs, geometry
Dino3d
🦖 Google Chrome T-Rex Run! in 3D (WebGL experiment)
Stars: ✭ 263 (-15.97%)
Mutual labels:  webgl, threejs
Enable3d
🕹️ Standalone 3D Framework / Physics for three.js (using ammo.js) / 3D extension for Phaser 3
Stars: ✭ 271 (-13.42%)
Mutual labels:  webgl, threejs
NodeMICMAC
A Lightweight REST API to Access MICMAC Photogrammetry and SFM Engine.
Stars: ✭ 54 (-82.75%)
Mutual labels:  geospatial, gis
Three Globe
WebGL Globe Data Visualization as a ThreeJS reusable 3D object
Stars: ✭ 270 (-13.74%)
Mutual labels:  webgl, threejs

3D 计算几何算法库(3D Computional Geometry Algorithm)

inspire by Wild Magic threejs/cga.js 开发交流群:284389784 2020 年 12 月 10 日 开发很久 typescript 全新版本更新 可以根据自己的需要编译成 js 版

概要

Computional Geometry Algorithm implement JavaScript,javascript 实现计算机几何算法库,实现比如像距离,相交,包含,偏移,平行垂直判断,正负位置等算法

如果你需要计算几何类的算法还没实现,可以 issue 提出,获取 Q 群联系我,优先实现

演示地址

案例:

文档与演示(国内镜像)网速快

文档与演示(github)

安装

npm install xtorcga -D
国内
cnpm install xtorcga -D

使用

  • 全部引用;:
import * as cga from "xtorcga";
function randomV3() {
  return cga.v3(
    Math.random() * 100 - 50,
    Math.random() * 100,
    Math.random() * 100 - 50
  );
}

var point = new cga.Point().copy(randomV3());
var seg = new cga.Segment(randomV3(), randomV3());
var result = point.distanceSegment(seg);
  • 按需求引用:
import { v3, Point, Segment } from "xtorcga";
function randomV3() {
  return v3(
    Math.random() * 100 - 50,
    Math.random() * 100,
    Math.random() * 100 - 50
  );
}

var point = new Point().copy(randomV3());
var seg = new Segment(randomV3(), randomV3());
var result = point.distanceSegment(seg);
  • 网页嵌入:直接下载使用 build 目录下面的 xtorcga,包含到项目中
<script src="xtorcga" />
或者
<script src="https://raw.githack.com/yszhao91/xtorcga/master/build/xtorcga" />
<script>
  var point = new cga.Point(1, 2, 3);
  var line = new cga.Line(
    new cga.Vector3(10, 10, 20),
    new cga.Vector3(20, 15, 10)
  );
  var result = point.distanceLine(line);
</script>

项目编译

npm run build //js 编译到build目录下生成xtorcga dist目录下生成每个文件的js和.d.ts
npm run dev  //运行项目,自己更改源码测试

对象的类名

  1. 点:Point
  2. 直线:Line
  3. 射线:Ray
  4. 线段:Segment
  5. 圆圈:Circle
  6. 平面:Plane
  7. 三角形:Triangle
  8. 矩形:Rectangle
  9. 圆盘:Disk
  10. 球体:Sphere
  11. 胶囊体: Capsule
  12. 包围盒:Box

已经实现算法

在同一平面点集的凸包

已完成

凸包

var convexHull = new ConvexHull(points, { planeNormal: cga.Vector3.UnitZ });
var hull = convexHull.hull;

delauny 三角网构建

三角剖分

var vs = [];
var data = [];
for (let i = 0; i < 10000; i++) {
  var x = Math.random() * 1000 - 500;
  var y = Math.random() * 1000 - 500;
  vs.push(new Vec3(x, y, 0));
  data.push(x, y);
}

var delaunator = Delaunator.from(data);
// 或者
var delaunator = Delaunator.fromVecs(vs);
var index = delaunator.triangles; //三角形索引

voronoi 图构建

完成

最近点对问题

点集合中最近找出距离最近的一对点 算法时间 O(nlogn)

完成

折线或者路径简化

折线或者路径中过密或者过直的点去除;
(2020  1  17 增加)
/**
 * 简化点集数组,折线,路径
 * @param {*} points 点集数组,折线,路径 ,继承Array
 * @param {*} maxDistance  简化最大距离 默认值0.1
 * @param {*} maxAngle  简化最大角度 弧度 默认值 Math.PI / 180 * 5
 */
simplifyPointList(points, maxDistance, maxAngle);

距离

一级目录与二级目录存在相应距离算法关系

  • Point
    • Point
    • Line
    • Ray
    • Segment
    • Circle
    • Plane
    • Triangle
    • Rectangle
    • Disk
    • Sphere
    • Capsule
  • Line
    • Line
    • Ray
    • Segment
    • Triangle (2020 年 1 月 17 增加)
  • Ray
    • Ray
    • Segment
    • Triangle (2020 年 1 月 17 增加)
  • Segment
    • Segment

相交

相交可以使用距离算法来实现,准确的说距离中的 closets 最近点在 distance 为 0(小于 1e-4,精度可以自定义)的时候也就是交点,parameters 表为 0 或 1 可以判断为端点相交

偏移

  • Segment

切割

  • Segment
    • Segment
  • Plane
    • Segment
    • Triangle

参考文章

计算机几何算法(CGA)专栏 https://zhuanlan.zhihu.com/c_1196384168014368768

展望

项目将会不断完善,如果你有好的想好可以提交你的想法。欢迎 star,让项目更进一步

讨论

QQ 群:284389784 by: dc

本人 2013 接触从事 webgl/threejs 工作,开发经验 7 年左右,一直以来都想着开源,结交更多志同道合的朋友,可接 threejs 项目

其他开源项目 看我的 github 主页 地址:https://github.com/yszhao91 欢迎大家 follow star,希望开源能帮到大家

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].