简体   繁体   English

如何重新格式化 GetVertices 以返回 (x1,y1,0), (x2,y2,0), (x3,y3,0);?

[英]How to re format GetVertices to return (x1,y1,0), (x2,y2,0), (x3,y3,0);?

So, I have added a constructor that makes it possible to create triangles with the expression new Triangle(x1, y1, x2, y2, x3, y3) where (x1,y1), (x2,y2), (x3,y3) are the three vertices of the triangle.因此,我添加了一个构造函数,它可以使用表达式 new Triangle(x1, y1, x2, y2, x3, y3) where (x1,y1), (x2,y2), (x3,y3) 创建三角形是三角形的三个顶点。 However, I need to make getVertices return (x1,y1,0), (x2,y2,0), (x3,y3,0);但是,我需要让 getVertices 返回 (x1,y1,0), (x2,y2,0), (x3,y3,0); that is, the coordinates given to the constructor, with coordinate z set to 0.也就是说,给构造函数的坐标,坐标 z 设置为 0。

below is code for a triangular prism, im trying to shorten/reformat so it works for a triangle, with a different formula.下面是三角棱镜的代码,我试图缩短/重新格式化,以便它适用于三角形,具有不同的公式。

 private List<Point> getVertices() {
        List<Point> result = new ArrayList<>();
        result.add(new Point(x1 + x, y1 + y, z - height / 2.0));
        result.add(new Point(x2 + x, y2 + y, z - height / 2.0));
        result.add(new Point(x3 + x, y3 + y, z - height / 2.0));
        result.add(new Point(x1 + x, y1 + y, z + height / 2.0));
        result.add(new Point(x2 + x, y2 + y, z + height / 2.0));
        result.add(new Point(x3 + x, y3 + y, z + height / 2.0));
        return result;

any help would be greatly appreciated任何帮助将不胜感激

Point is a 2 dimensional coordinate of x and y . Point 是x and y的二维坐标。 You would need to define your own class for a 3 dimensional x,y,z .您需要为 3 维x,y,z定义自己的 class 。 Call the class Point3D调用 class Point3D

class Point3D {
   int x, y, z;
   public Point3D (int x, int y, int z) {
      this.x = x;
      this.y = y;
      this.z = z;
  }
  public int getX() {
      return x;
  }
 public int getY() {
      return y;
  }
 public int getZ() {
      return z;
  }
}

That is not difficult but your List<Point3D> may not be compatible with something that expects List<Point> so you need to consider that.这并不难,但您的List<Point3D>可能与期望List<Point>的东西不兼容,因此您需要考虑这一点。

You could also subclass the Point class.您还可以对Point class 进行子类化。 But there are quite a few methods you would need to add if you wanted the same functionality for a 3D point.但是,如果您希望 3D 点具有相同的功能,则需要添加很多方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何划分字符串(x1,y1)(x2,y2)格式 - How to divide string (x1,y1)(x2,y2) format 给定两个点 A(x1,y1) &amp; B(x2,y2),我想在球面上找到第三点 C(x3,y3) 和线 AB 之间的距离和 AD 的长度 - Given two points A(x1,y1) & B(x2,y2), I want to find the distance between the third point C(x3,y3) and line AB and length of AD on spherical surface 按钮无法绘制具有坐标(x1,x2,y1,y2)的折线图 - Button not working to draw line graph having its coordinate (x1, x2, y1, y2) 如果我们知道距离x1,y1,y2,则计算x2 - Calculate x2 if we know distance, x1, y1, y2 为什么 x *= (y1*y2*y3)/z1 没有给出与 JAVA 中的 x = x * (y1*y2*y3)/z1 相同的答案 - Why is x *= (y1*y2*y3)/z1 not giving the same answer as x = x * (y1*y2*y3)/z1 in JAVA 如何确定百万数据点中的哪些点 (x,y) 位于矩形 (x1, x2, y1, y2) 所描述的区域内? - How to determine which points (x,y) out of million data points lie inside the area described by a rectangle (x1, x2, y1, y2)? 在java中以给定速度以直线将对象从点(x1,y1)移动到点(x2,y2)的方法 - Method to move an object from point(x1,y1) to point(x2,y2) at a given speed in a straight line in java 在X1 y1 X2 y2形式的10,000个点的文件中,如何检测至少四个正方形? 爪哇 - In a file of 10,000 points of the form X1 y1 X2 y2 ,,, How to detect at least 4 which form a square ? java 如何使用Quartz库每天在XX:XX处安排从日期X1 / Y1 / Z1到日期X2 / Y2 / Z2的某些任务? - How can I use Quartz library to schedule some task from date X1/Y1/Z1 to date X2/Y2/Z2 at XX:XX every day? 将位图从(x,y)移到(x2,y2)如何计算起始和目标之间的x,y值 - move bitmap from (x,y) to (x2,y2) how to compute x,y values between start and destination
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM