【问题标题】:How do I split a SVG shape into several shapes in Java or Processing?如何在 Java 或 Processing 中将 SVG 形状拆分为多个形状?
【发布时间】:2017-08-04 21:54:27
【问题描述】:

例如,给定一个圆形 SVG 形状,上面有五个等距的点。我想根据这些点将圆分成五个弧。在下图中,其中一条弧线是红色的。我该怎么做呢?特别是,我想使用 geomerative 库(来自 Processing),但也愿意使用 Java 中的其他解决方案。

【问题讨论】:

    标签: java svg processing


    【解决方案1】:

    为什么不使用 Processing 的 arc() 函数简单地绘制五个弧? 您只需要计算 5 个部分中每个部分的 72 度角增量:

    int sides = 5;
    //360 degrees / 5 sides, but in radians (what arc() likes)
    float angleIncrement = TWO_PI / sides;
    float diameter = 350;
    
    void setup(){
      size(400,400);
      colorMode(HSB,sides,100,100);
      noFill();
      strokeWeight(30);
      strokeCap(SQUARE);
    }
    void draw(){
      background(0,0,100);
    
      for(int i = 0 ; i < sides; i++){
        //72 degrees * each side to which we subtract a 90 degrees offset to first point is towards the top, not the side
        float angle = (angleIncrement * i)-HALF_PI;
    
        stroke(i,100,100);
        arc(200,200,diameter,diameter,angle,angle+angleIncrement);
      }
    }
    

    您实际上可以将其作为演示运行:

    var sides = 5;
    //360 degrees / 5 sides, but in radians (what arc() likes)
    var angleIncrement;
    var diameter = 350;
    
    function setup(){
      createCanvas(400,400);
      colorMode(HSB,sides,100,100);
      noFill();
      strokeWeight(30);
      strokeCap(SQUARE);
      
      angleIncrement = TWO_PI / sides;
    }
    function draw(){
      background(0,0,100);
      
      for(var i = 0 ; i < sides; i++){
        //72 degrees * each side to which we subtract a 90 degrees offset to first point is towards the top, not the side
        var angle = (angleIncrement * i)-HALF_PI;
        
        stroke(i,100,100);
        arc(200,200,diameter,diameter,angle,angle+angleIncrement);
      }
    }
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.min.js"&gt;&lt;/script&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-29
      • 1970-01-01
      • 2014-03-20
      相关资源
      最近更新 更多