2d-polygon-boolean 中文文档教程

发布于 9年前 浏览 28 项目主页 更新于 3年前

polygon.clip

Greiner-Kai“高效裁剪任意多边形”论文

install

npm install 2d-polygon-boolean

use

signature

var polygons = polygonBoolean(array1, array2, mode)

其中mode是字符串(相交),or (union), not (cut)

polygons 是数组的数组,

例如

  [
    [
      [0, 0],
      [0, 1],
      [1, 1]
    ]
  ]

example

var polygonBoolean = require('2d-polygon-boolean');

var subject = [
  [0, 0],
  [100, 0],
  [100, 100],
  [0, 100]
];

var clip = [
  [90, 90],
  [110, 90],
  [110, 110],
  [90, 110],
  [90, 90]
];


var union = polygonBoolean(subject, clip, 'or');
console.log('union results', union);

/*
union results [ [ [ 100, 90 ],
    [ 100, 0 ],
    [ 0, 0 ],
    [ 0, 100 ],
    [ 90, 100 ],
    [ 90, 110 ],
    [ 110, 110 ],
    [ 110, 90 ] ] ]
*/

var cut = polygonBoolean(subject, clip, 'not');
console.log('cut results', cut);

/*
cut results [ [ [ 100, 90 ],
    [ 100, 0 ],
    [ 0, 0 ],
    [ 0, 100 ],
    [ 90, 100 ],
    [ 90, 90 ] ] ]
*/

var intersect = polygonBoolean(subject, clip, 'and');
console.log('intersect results', intersect);

/*
intersect results [ [ [ 100, 90 ], [ 100, 100 ], [ 90, 100 ], [ 90, 90 ] ] ]
*/

license

MIT

polygon.clip

Implementation of the Greiner-Kai "efficient clipping of arbitrary polygons" paper

install

npm install 2d-polygon-boolean

use

signature

var polygons = polygonBoolean(array1, array2, mode)

Where mode is the string and (intersect), or (union), not (cut)

polygons is an array of arrays of arrays

e.g

  [
    [
      [0, 0],
      [0, 1],
      [1, 1]
    ]
  ]

example

var polygonBoolean = require('2d-polygon-boolean');

var subject = [
  [0, 0],
  [100, 0],
  [100, 100],
  [0, 100]
];

var clip = [
  [90, 90],
  [110, 90],
  [110, 110],
  [90, 110],
  [90, 90]
];


var union = polygonBoolean(subject, clip, 'or');
console.log('union results', union);

/*
union results [ [ [ 100, 90 ],
    [ 100, 0 ],
    [ 0, 0 ],
    [ 0, 100 ],
    [ 90, 100 ],
    [ 90, 110 ],
    [ 110, 110 ],
    [ 110, 90 ] ] ]
*/

var cut = polygonBoolean(subject, clip, 'not');
console.log('cut results', cut);

/*
cut results [ [ [ 100, 90 ],
    [ 100, 0 ],
    [ 0, 0 ],
    [ 0, 100 ],
    [ 90, 100 ],
    [ 90, 90 ] ] ]
*/

var intersect = polygonBoolean(subject, clip, 'and');
console.log('intersect results', intersect);

/*
intersect results [ [ [ 100, 90 ], [ 100, 100 ], [ 90, 100 ], [ 90, 90 ] ] ]
*/

license

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文