我有一个问题让我疯了! :)我现在一直在日夜工作:):)
我的目标是什么? I'm looking for a way for inward/outward polygon offsetting
在外面说2。 2里面。使用Illustrator很容易:)
到目前为止我的方法
float getAngle = (atan((P1.y-P2.y)/(P1.x-p2.x))) * (180/PI) ;
2
// ( COS(angle) = (adjacent side) / (hypotenuse) ) || 2 = 6 / 3
// ( COS(angle) * (hypotenuse) = (adjacent side) || 2 * 3 = 6
// ( SIN(angle) = (opposite side) / (hypotenuse) ) || 2 = 6 / 3
// ( SIN(angle) * (hypotenuse) = (opposite side) || 2 * 3 = 6
我的问题
我想从你这里得到什么?
我无法绕过如何将线偏移保持在第一/中心线之外。
答案 0 :(得分:0)
你可以放弃缩放顶点吗?
void setup(){
size(400,400);
PVector[] originalPath = randomPath(7,100);
PVector[] insetPath = scalePoints(originalPath,0.75);
PVector[] outsetPath = scalePoints(originalPath,1.25);
background(255);
noFill();
translate(width * .5, height * .5);
stroke(0,192,0);
drawPath(originalPath);
stroke(192,0,0);
drawPath(insetPath);
stroke(0,0,192);
drawPath(outsetPath);
fill(0);
text("original path",originalPath[0].x,originalPath[0].y);
text("inset path",insetPath[1].x,insetPath[1].y);
text("outset path",outsetPath[2].x,outsetPath[2].y);
text("click\nto\nreset",0,0);
}
void drawPath(PVector[] pts){
beginShape();
for(PVector p : pts) vertex(p.x,p.y);
endShape(CLOSE);
}
PVector[] scalePoints(PVector[] pts,float scale){
int numPoints = pts.length;
PVector[] result = new PVector[numPoints];
for(int i = 0 ; i < numPoints; i++){
result[i] = pts[i].get();
result[i].mult(scale);
}
return result;
}
PVector[] randomPath(int numPoints,float r){
PVector[] result = new PVector[numPoints];
float ai = TWO_PI / numPoints;
for(int i = 0 ; i < numPoints; i++){
float radius = random(r-r*.25,r+r*.25);
result[i] = new PVector(cos(ai * i) * radius, sin(ai * i) * radius);
}
return result;
}
void mousePressed(){
setup();
}
void draw(){}