PGS

PGS

Processing几何算法库 丰富2D图形创作

Processing Geometry Suite是一个2D几何算法开源库,提供丰富的几何操作功能。它支持布尔运算、几何变换、轮廓生成和形态学处理等,便于实现复杂的几何操作和可视化效果。该库采用静态方法和Processing原生数据类型,注重直观的可视化表现,适合各种创意编程和数据可视化项目使用。

Processing几何算法2D图形可视化PShapeGithub开源项目

Lines of Code

Processing Geometry Suite

Processing Geometry Suite is a software project that provides easy access to 2D geometric algorithms in the form of a Processing library. Over time it has grown to include an incredibly comprehensive range of algorithms.

The focus of the library is on visualisation rather than providing underlying data structures. To this end all methods in the library are static and most of them take in and return PShapes or PVectors.

Docs are hosted via GitHub Pages here.

Overview

Library functionality is split over the following classes:

  • PGS_CirclePacking
    • Circle packings of shapes, subject to varying constraints and patterns of tangencies
  • PGS_Coloring
    • Minimal colorings of meshes (or mesh-like shapes)
  • PGS_Construction
    • Construct uncommon/interesting 2D primitives
  • PGS_Contour
    • Methods that produce various contours from shapes: medial axes, straight skeletons, offset curves, etc.
  • PGS_Conversion
    • Conversion between Processing PShapes and JTS Geometries (amongst other formats)
  • PGS_Hull
    • Convex and concave hulls of polygons and point sets
  • PGS_Meshing
    • Mesh generation (excluding triangulation) and processing
  • PGS_Morphology
    • Methods that affect the geometry or topology of shapes (buffering, simplification, smoothing, etc.)
  • PGS_Optimisation
    • Solve geometric optimisation problems, such as finding the maximum inscribed circle, or the closest vertex to a coordinate
  • PGS_PointSet
    • Generates sets of 2D points having a variety of different distributions and constraints
  • PGS_Processing
    • Methods that process a shape in some way: compute hulls, partition, slice, etc.
  • PGS_SegmentSet
    • Generates sets of random non-intersecting line segments
  • PGS_ShapeBoolean
    • Boolean set-operations for 2D shapes
  • PGS_ShapePredicates
    • Various shape metrics (area, circularity, etc.) and predicates ("do these shapes intersect?")
  • PGS_Tiling
    • Tiling, tessellation and subdivision of the plane using periodic or non-periodic geometric shapes.
  • PGS_Transformation
    • Various geometric and affine transformations that affect vertex coordinates
  • PGS_Triangulation
    • Delaunay triangulation (constrained and refined) and earcut triangulation of shapes and point sets
  • PGS_Voronoi
    • Voronoi Diagrams of shapes and point sets

Installation

<details><summary>Processing IDE — Quick</summary> <p>

Download the latest PGS.jar from releases and simply drag-and-drop it onto the Processing IDE.

</p> </details> <details><summary>Processing IDE — Permanently</summary> <p>

Download the latest PGS.jar from releases and save it to Documents\Processing\libraries\PGS\library.

Result: Documents\Processing\libraries\PGS\library\PGS.jar.

(Note the .jar and the folder must be called PGS — rename the .jar if this is not the case).

</p> </details> <details><summary>Maven/Gradle</summary> <p>

PGS is hosted as an artifact for use in Maven or Gradle projects via Jitpack — follow the instructions there (very easy).

</p> </details>

Examples

A number of example Processing sketches are provided in examples.

<p float="middle"> <a href="examples/partitionSmooth"><img src="resources/examples/partitionSmooth.png" alt="" width="24%"/></a> <a href="examples/textOffsetCurves"><img src="resources/examples/textOffsetCurves.png" alt="" width="24%"/></a> <a href="examples/ripplingTriangles"><img src="resources/examples/ripplingTriangles.png" alt="" width="24%"/></a> <a href="examples/contourMap"><img src="resources/examples/contourMap.png" alt="" width="24%"/></a> </p>

Illustrations

Much of the functionality (but by no means all) is demonstrated below:

2D Boolean Operations

<table> <tr> <td align="center" valign="center"><b>Union</td> <td align="center" valign="center"><b>Intersection</td> <td align="center" valign="center"><b>Subtraction</td> <td align="center" valign="center"><b>Symmetric Difference</td> </tr> <tr> <td valign="top"><img src="resources/boolean/union.gif"></td> <td valign="top"><img src="resources/boolean/intersect.gif"></td> <td valign="top"><img src="resources/boolean/subtract.gif"></td> <td valign="top" ><img src="resources/boolean/symDifference.gif"></td> </tr> <tr> <td align="center" valign="center"><b>Complement</td> <td align="center" valign="center"><b>Mesh Union</td> <td align="center" valign="center"><b>Mesh Intersection</td> <td align="center" valign="center"><b>Mesh Subtraction</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/boolean/complement.png"></td> <td valign="top" width="25%"><img src="resources/boolean/meshUnion.gif"></td> <td valign="top" width="25%"><img src="resources/boolean/intersectMesh.gif"></td> <td valign="top" width="25%"><img src="resources/boolean/subtractMesh.gif"></td> </tr> </table>

Transformation

<table> <tr> <td align="center" valign="center" colspan="2"><b>Rotate Around</td> <td align="center" valign="center"><b>Translate To</td> <td align="center" valign="center"><b>Touch Scale</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/transform/rotateCenter.gif"></td> <td valign="top" width="25%"><img src="resources/transform/rotate.gif"></td> <td valign="top" width="25%"><img src="resources/transform/translateTo.gif"></td> <td valign="top" width="25%"><img src="resources/transform/touchScale.gif"></td> </tr> <tr> <td align="center" valign="center" colspan="2">Rotate a shape around its centroid or an arbitrary point.</td> <td align="center" valign="center">Translate a shape such that its centroid matches some position.</td> <td align="center" valign="center">Scale one shape such that it touches another.</td> </tr> <tr> <td align="center" valign="center"><b>Resize</td> <td align="center" valign="center"><b>Homothetic Transformation</td> <td align="center" valign="center"><b>Shear</td> <td align="center" valign="center"><b>Align</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/transform/resize.gif"></td> <td valign="top" width="25%"><img src="resources/transform/homothetic.gif"></td> <td valign="top" width="25%"><img src="resources/transform/shear.gif"></td> <td valign="top" width="25%"><img src="resources/transform/align.gif"></td> </tr> <tr> <td align="center" valign="center"></td> <td align="center" valign="center">Projection-transform a shape with respect to a fixed point.</td> <td align="center" valign="center"></td> <td align="center" valign="center">Maximum-overlap alignment.</td> </tr> </table>

Geometric Predicates & Metrics

<table> <tr> <td align="center" valign="center"><b>Intersects</td> <td align="center" valign="center"><b>Contains Shape</td> <td align="center" valign="center"><b>Contains Point</td> <td align="center" valign="center"><b>Containing Cell</td> </tr> <tr> <td valign="top" align="center" width="25%"> <img src="resources/predicate/intersect.gif"><br>Do shapes intersect with each other?</td> <td valign="top" align="center" width="25%"><img src="resources/predicate/contains.gif"><br>Does one shape fully contain another?</td> <td valign="top" align="center" width="25%"><img src="resources/predicate/containsPoint.gif"><br>For individual points and point sets.</td> <td valign="top" align="center" width="25%"><img src="resources/predicate/containingCell.gif"><br>Which cell contains the query point?</td> </table>

Metrics

  • Length/perimeter
  • Width & Height
  • Diameter
  • Circularity
  • Similarity
  • Sphericity
  • Elongation
  • Density
  • Holes
  • Maximum interior angle
  • Is simple?
  • Is convex?
  • Equal? (structural and topological equivalence)
  • Distance
  • Area
  • Centroid
  • Median

Contour

<table> <tr> <td align="center" valign="center" colspan="2"><b>Isolines</td> <td align="center" valign="center" colspan="2"><b>Offset Curves</td> </tr> <tr> <td valign="top"><img src="resources/contour/isolines.gif"></td> <td valign="top"><img src="resources/contour/isolines2.gif"></td> <td valign="top"><img src="resources/contour/miteredInterior.gif"></td> <td valign="top"><img src="resources/contour/miteredExterior.gif"></td> </tr> </tr> <tr> <td align="center" valign="center" colspan="2">Isolines from intra-shape euclidean distance, or point sets.</td> <td align="center" valign="center" colspan="2">Inner and exterior offset curves; based on <i>miter, bevel</i> or <i>round</i> offset styles.</td> </tr> <tr> <td align="center" valign="center"><b>Straight Skeleton</td> <td align="center" valign="center" colspan="2"><b>Medial Axis</td> <td align="center" valign="center"><b>Chordal Axis</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/contour/straightSkeleton.png"></td> <td valign="top" width="25%"><img src="resources/contour/medialAxis.gif"></td> <td valign="top" width="25%"><img src="resources/contour/medialAxis.png"></td> <td valign="top" width="25%"><img src="resources/contour/chordalAxis.png"></td> </tr> </tr> <tr> <td align="center" valign="center"></td> <td align="center" valign="center" colspan="2">Medial axis transform with feature pruning via distance, area or <i>axial angle</i>. </td> <td align="center" valign="center">Chordal Axis Transform</td> </tr> <tr> <td align="center" valign="center"><b>Distance Field</td> <td align="center" valign="center"><b>Center Line</td> </tr> <tr> <td valign="top"><img src="resources/contour/distanceField.png"></td> <td valign="top"><img src="resources/contour/centerLine.gif"></td> </tr> </tr> <tr> <td align="center" valign="center">A contour map based on a distance field of a shape</td> </tr> </table>

Morphology

<table> <tr> <td align="center" valign="center"><b>Buffer</td> <td align="center" valign="center"><b>Erosion-Dilation</td> <td align="center" valign="center" colspan="2"><b>Minkowski Addition</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/morphology/buffer.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/erosionDilation.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/minkSum.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/minkDiff.gif"></td> </tr> <tr> <td align="center" valign="center"></td> <td align="center" valign="center">A negative followed by a positive buffer (in a single operation).</td> <td align="center" valign="center" colspan="2">Minkowski sum and difference (a.k.a buffer one shape using another shape; the examples add a rotating & growing triangle).</td> </tr> <tr> <td align="center" valign="center"><b>Smoothing</td> <td align="center" valign="center"><b>Gaussian Smoothing</td> <td align="center" valign="center" colspan="2"><b>Rounding</td> </tr> <tr> <td valign="top"><img src="resources/morphology/smooth.gif"></td> <td valign="top"><img src="resources/morphology/gaussianSmooth.gif"></td> <td valign="top"><img src="resources/morphology/round.gif"></td> <td valign="top" ><img src="resources/morphology/round2.gif"></td> </tr> <tr> <td align="center" valign="center"><b>Radial Warp</td> <td align="center" valign="center"><b>Sine Warp</td> <td align="center" valign="center" colspan="2"><b>Field Warp</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/morphology/radialWarp2.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/sineWarp.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/fieldWarp.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/fieldWarp2.gif"></td> </tr> <tr> <td align="center" valign="center"><b>Simplification</td> <td align="center" valign="center" colspan="2"><b>Chaikin Cutting</td> <td align="center" valign="center" colspan="2"><b>Interpolation</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/morphology/simplifyVW.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/chaikinCut1.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/chaikinCut2.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/morph.gif"></td> </tr> <tr> <td align="center" valign="center"><b>Variable Buffer</td> <td align="center" valign="center"><b>Precision Reduction</td> <td align="center" valign="center"><b>Hobby Curve Simplification</td> <td align="center" valign="center"><b>Elliptic Fourier Smoothing</td> </tr> <tr> <td valign="top" width="25%"><img src="resources/morphology/variableBuffer.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/reducePrecision.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/hobbySimplify.gif"></td> <td valign="top" width="25%"><img src="resources/morphology/ellipticFourierSmooth.gif"></td> </tr> </table>

Hull

<table> <tr> <td align="center" valign="center" colspan="3"><b>Concave Hull</td> <td align="center"

编辑推荐精选

扣子-AI办公

扣子-AI办公

职场AI,就用扣子

AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!

堆友

堆友

多风格AI绘画神器

堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

图像生成AI工具AI反应堆AI工具箱AI绘画GOAI艺术字堆友相机AI图像热门
码上飞

码上飞

零代码AI应用开发平台

零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

下拉加载更多