通过三个坐标填充三角形内的颜色

fill color inside triangle by three co-ordinates

我正在使用点云。我有3D点.

假设:点 P(x,y,z)、点 Q(x,y,z)、点 R(x,y,z) 假设这些点为三角形 PQR,我们进一步进行。

像这样的三角形: .

如何填充绘制的这些点内的区域,使三角形充满颜色。

像这样: .

我的研究可能有所帮助:

编辑:

成功之路:

public void make_polygon(float[] points_x,float[] points_y,float[] points_z)
{
    Material mSphereMaterial_z = new Material();
    //mSphereMaterial_z.setColor(Color.BLUE);
    Bitmap p_z_bitty = getTriangleBitmap(BitmapFactory.decodeResource(mContext.getResources(),R.drawable.label_bg_sm),5,points_x,points_y,points_z);
    Texture t = new Texture("text",p_z_bitty);
    try {
        mSphereMaterial_z.addTexture(t);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    Object3D p_z =  new Plane();
    p_z.setPosition(points_x[0],points_y[1],points_z[2]);
    p_z.setMaterial(mSphereMaterial_z);
    p_z.setDoubleSided(true);
    getCurrentScene().addChild(p_z);
}

public static Bitmap getTriangleBitmap(Bitmap bitmap, int radius,float[] a,float[] b,float[] c) {
    Bitmap finalBitmap;
    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
                false);
    else
        finalBitmap = bitmap;
    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

     //        Point point1_draw = new Point(75, 0);
     //        Point point2_draw = new Point(0, 180);
     //        Point point3_draw = new Point(180, 180);
    PointF point1_draw = new PointF(a[0],a[1]);
    PointF point2_draw = new PointF(b[0], b[1]);
    PointF point3_draw = new PointF(c[0],c[1] );

    Path path = new Path();
    path.moveTo(point1_draw.x, point1_draw.y);
    path.lineTo(point2_draw.x, point2_draw.y);
    path.lineTo(point3_draw.x, point3_draw.y);
    path.lineTo(point1_draw.x, point1_draw.y);
    path.close();
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawPath(path, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}

现在结果是:

有人可以指导我或为 Android java 推荐一些关于它的文章吗?

如果需要更多信息/代码,应提供。

您应该能够通过简单地将三角形的顶点传递给 Rajawali 来完成此操作,以便将三角形绘制为图元。这样您就可以避免使用 Canvas 或绘制位图并简化渲染。

// p, q, and r are triangle vertices and are of the form {x, y, z}.
public void make_triangle(float[] p, float[] q, float[] r)
{
    Object3D triangle = new Object3D();

    // Copy three points into a flat array as our vertices.
    float[] vertices = new float[3 * 3];
    for (int i = 0; i < 3; i++) {
        vertices[i] = p[i];
        vertices[3 + i] = q[i];
        vertices[6 + i] = r[i];
    }

    // Set up index buffer to point at our three vertices and thus draw one triangle.
    int[] indices = new int[3];
    for (int i = 0; i < 3; i++) {
        indices[i] = i;
    }

    // Set up the rendering data.
    triangle.setData(vertices, null, null, null, indices, true);

    // Render the triangle double sided.
    triangle.setDoubleSided(true);

    // Use a blue material.
    Material material = new Material();
    material.setColor(Color.BLUE);
    triangle.setMaterial(material);

    // Add the triangle to the current scene.
    getCurrentScene().addChild(triangle);
}