【发布时间】:2017-08-04 21:54:27
【问题描述】:
例如,给定一个圆形 SVG 形状,上面有五个等距的点。我想根据这些点将圆分成五个弧。在下图中,其中一条弧线是红色的。我该怎么做呢?特别是,我想使用 geomerative 库(来自 Processing),但也愿意使用 Java 中的其他解决方案。
【问题讨论】:
标签: java svg processing
例如,给定一个圆形 SVG 形状,上面有五个等距的点。我想根据这些点将圆分成五个弧。在下图中,其中一条弧线是红色的。我该怎么做呢?特别是,我想使用 geomerative 库(来自 Processing),但也愿意使用 Java 中的其他解决方案。
【问题讨论】:
标签: java svg processing
为什么不使用 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);
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.min.js"></script>
【讨论】: