【问题标题】:Processing 3 - PVector Path offset // inward/outward polygon offsetting处理 3 - PVector 路径偏移 // 向内/向外多边形偏移
【发布时间】:2017-01-23 16:54:44
【问题描述】:

我有一个问题让我发疯! :) 我现在日以继夜地工作 :) :)

我的目标是什么?

在外面说 2。 2里面。使用 Illustrator 很容易:)

我目前的做法

  1. 顺时针工作。获取 P1 和 P2 之间的角度
  2. 使用三角法计算 X 和 Y 偏移
  3. 将 X 和 Y 偏移添加到 P1 和 P2。这就是我得到 P1 和 P2 之间角度的方法:
float getAngle = (atan((P1.y-P2.y)/(P1.x-p2.x))) * (180/PI) ;
// ( 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

我的问题

  • 我知道如何偏移路径。但仅在一侧。总是 +x 和 -Y。所以这就是结果。几乎就像完全移动路径一样。而不是四处偏移。:

它需要保持在中心/原始线之外。

我想从你那里得到什么?

  • 有这样做的逻辑/公式吗?
  • 或者有没有图书馆已经有这个??

我无法理解如何将线偏移保持在第一条/中心线之外。

【问题讨论】:

    标签: coordinates processing polygon offset


    【解决方案1】:

    你能不缩放顶点吗?

    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(){}
    

    【讨论】:

    • cr*p,非常抱歉耽搁了。我不知何故没有收到通知.. 不过谢谢!我要调查一下。看起来很有希望!
    • @Tim 上面的 sn-p 你运气好吗?
    猜你喜欢
    • 1970-01-01
    • 2011-07-20
    • 2019-05-30
    • 1970-01-01
    • 2012-10-26
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多