@Test public void testGetRandomPoint() { Triangle triangle=new Triangle(new Vector3(0, 0), new Vector3(10, 0), new Vector3(0, 10), 1); Vector3 vector3=new Vector3(); for(int i=0;i<100000000;i++) { triangle.getRandomPoint(vector3); } }
public Vector3 getRandomPoint(Vector3 out) { final float sr1 = (float) Math.sqrt(MathUtil.random()); final float r2 = MathUtil.random(); final float k1 = 1 - sr1; final float k2 = sr1 * (1 - r2); final float k3 = sr1 * r2; out.x = k1 * a.x + k2 * b.x + k3 * c.x; out.y = k1 * a.y + k2 * b.y + k3 * c.y; out.z = k1 * a.z + k2 * b.z + k3 * c.z; return out; }
Triangle implements Shape { public Vector3 getRandomPoint(Vector3 out) { final float sr1 = (float) Math.sqrt(MathUtil.random()); final float r2 = MathUtil.random(); final float k1 = 1 - sr1; final float k2 = sr1 * (1 - r2); final float k3 = sr1 * r2; out.x = k1 * a.x + k2 * b.x + k3 * c.x; out.y = k1 * a.y + k2 * b.y + k3 * c.y; out.z = k1 * a.z + k2 * b.z + k3 * c.z; return out; } }
Triangle implements Shape { public Vector3 getRandomPoint(Vector3 out) { final float sr1 = (float) Math.sqrt(MathUtil.random()); final float r2 = MathUtil.random(); final float k1 = 1 - sr1; final float k2 = sr1 * (1 - r2); final float k3 = sr1 * r2; out.x = k1 * a.x + k2 * b.x + k3 * c.x; out.y = k1 * a.y + k2 * b.y + k3 * c.y; out.z = k1 * a.z + k2 * b.z + k3 * c.z; return out; } Triangle(Vector3 a, Vector3 b, Vector3 c, int index,int ...vectorIndex); }
Triangle implements Shape { public Vector3 getRandomPoint(Vector3 out) { final float sr1 = (float) Math.sqrt(MathUtil.random()); final float r2 = MathUtil.random(); final float k1 = 1 - sr1; final float k2 = sr1 * (1 - r2); final float k3 = sr1 * r2; out.x = k1 * a.x + k2 * b.x + k3 * c.x; out.y = k1 * a.y + k2 * b.y + k3 * c.y; out.z = k1 * a.z + k2 * b.z + k3 * c.z; return out; } Triangle(Vector3 a, Vector3 b, Vector3 c, int index,int ...vectorIndex); @Override String toString(); int getIndex(); List<Connection<Triangle>> getConnections(); float getAngle(Vector3 reference); Vector3 getRandomPoint(Vector3 out); float area(); float area2D(); boolean isInnerPoint(Vector3 point); @Override int hashCode(); @Override boolean equals(Object obj); @Override Rectangle getBounds(); @Override Rectangle2D getBounds2D(); @Override boolean contains(double x, double y); @Override boolean contains(Point2D p); @Override boolean intersects(double x, double y, double w, double h); @Override boolean intersects(Rectangle2D r); @Override boolean contains(double x, double y, double w, double h); @Override boolean contains(Rectangle2D r); @Override PathIterator getPathIterator(AffineTransform at); @Override PathIterator getPathIterator(AffineTransform at, double flatness); }
Triangle implements Shape { public Vector3 getRandomPoint(Vector3 out) { final float sr1 = (float) Math.sqrt(MathUtil.random()); final float r2 = MathUtil.random(); final float k1 = 1 - sr1; final float k2 = sr1 * (1 - r2); final float k3 = sr1 * r2; out.x = k1 * a.x + k2 * b.x + k3 * c.x; out.y = k1 * a.y + k2 * b.y + k3 * c.y; out.z = k1 * a.z + k2 * b.z + k3 * c.z; return out; } Triangle(Vector3 a, Vector3 b, Vector3 c, int index,int ...vectorIndex); @Override String toString(); int getIndex(); List<Connection<Triangle>> getConnections(); float getAngle(Vector3 reference); Vector3 getRandomPoint(Vector3 out); float area(); float area2D(); boolean isInnerPoint(Vector3 point); @Override int hashCode(); @Override boolean equals(Object obj); @Override Rectangle getBounds(); @Override Rectangle2D getBounds2D(); @Override boolean contains(double x, double y); @Override boolean contains(Point2D p); @Override boolean intersects(double x, double y, double w, double h); @Override boolean intersects(Rectangle2D r); @Override boolean contains(double x, double y, double w, double h); @Override boolean contains(Rectangle2D r); @Override PathIterator getPathIterator(AffineTransform at); @Override PathIterator getPathIterator(AffineTransform at, double flatness); public int index; public Vector3 a; public Vector3 b; public Vector3 c; public float y; public Vector3 center; transient List<Connection<Triangle>> connections; public int[] vectorIndex; }