【问题标题】:How to get minimum & maximum points from bounding box in Processing?如何从处理中的边界框获取最小和最大点?
【发布时间】:2020-07-23 17:00:31
【问题描述】:

我已经了解了 Box 的所有角落,但我不知道如何在 Python 处理中确定最小和最大 x 和 y 坐标。

这里是代码

add_library('peasycam')

def setup():
    size(900, 800, P3D)
    global camera
    camera = PeasyCam(this, 0, 0, 0, 500)

def draw():
    background(255, 255, 255)
    lights()
    directionalLight(0, 255, 0, 0.5, 1, 0.1)

    pushMatrix()
    fill(100, 100, 100)
    box(100, 100, 100)

    corner(50, 50, 50)
    cx1 = screenX(0, 0, 0)
    cy1 = screenY(0, 0, 0)

    corner(-100, 0, 0)
    cx2 = screenX(0, 0, 0)
    cy2 = screenY(0, 0, 0)

    corner(0, -100, 0)
    cx3 = screenX(0, 0, 0)
    cy3 = screenY(0, 0, 0)

    corner(100, 0, 0)
    cx4 = screenX(0, 0, 0)
    cy4 = screenY(0, 0, 0)

    corner(-100, 0, -100)
    cx5 = screenX(0, 0, 0)
    cy5 = screenY(0, 0, 0)

    corner(100, 0, 0)
    cx6 = screenX(0, 0, 0)
    cy6 = screenY(0, 0, 0)

    corner(0, 100, 0)
    cx7 = screenX(0, 0, 0)
    cy7 = screenY(0, 0, 0)

    corner(-100, 0, 0)
    cx8 = screenX(0, 0, 0)
    cy8 = screenY(0, 0, 0)
    popMatrix()
 
def corner(x, y, z):
    translate(x, y, z)
    box(10);

我研究了很多,但没有找到更好的解决方案。

提前致谢:)

【问题讨论】:

    标签: python 3d processing


    【解决方案1】:

    我在下面附上了工作代码的 Java 实现。您可以通过遍历 PVector 数组来访问坐标。 我建议你可以改用 Java 来做这个项目,因为 Processing.py 目前有点不稳定,从长远来看,Java 将被证明更加健壮。但是,如果您对 Python 更熟悉,那么坚持使用它是没有问题的。

    import peasy.*;
    
    PeasyCam camera;
    PVector[] corners;
    
    void setup() {
      size(900, 800, P3D);
      camera = new PeasyCam(this, 0, 0, 0, 500);
      
      corners = new PVector[8];
      int index = 0;
      for(int x = 0; x < 2; x++) {
        for(int y = 0; y < 2; y++) {
          for(int z = 0; z < 2; z++) {
            corners[index] = new PVector(mapCorner(x), mapCorner(y), mapCorner(z));
            index++;
          }
        }
      }
    }
    
    void draw() {
      background(255, 255, 255);
      lights();
      directionalLight(0, 255, 0, 0.5, 1, 0.1);
    
      pushMatrix();
        fill(100, 100, 100);
        box(100, 100, 100);
        for(PVector v : corners) {
          corner(v.x, v.y, v.z);
        }
      popMatrix();
    }
    
    void corner(float x, float y, float z) {
      pushMatrix();
        translate(x, y, z);
        box(10);
      popMatrix();
    }
    
    float mapCorner(float x) {
      return map(x, 0, 1, -50, 50);
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 2023-02-25
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      相关资源
      最近更新 更多