如何在加工过程中从边界框中获取最小点和最大点?

2024-06-12 16:47:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经得到了盒子的所有角落,但我不知道如何在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);

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

提前感谢:)


Tags: boxadd密码sizedefsetuplibrarycamera
1条回答
网友
1楼 · 发布于 2024-06-12 16:47:10

我在下面附上了一个工作代码的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);
}

希望这有帮助

相关问题 更多 >