1

ポリゴンなどの頂点を使用してオブジェクトを描画し、その表面と周囲長を取得した経験はありますか。

ジオメトリは、 https://play.google.com/store/apps/details?id = de.hms.xconstructionと同様の頂点または座標を使用して手動で描画され、形状が形成されます。これらの閉じた形状の表面を取得する必要があります。

ネット上で利用可能な例はありますか?

前もって感謝します。

4

1 に答える 1

0

次のコードは良いスタートになると思います。基本的に、すべてのユーザータッチの間に線を引きます。

public class TestActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new DrawingView(this));
}

class DrawingView extends SurfaceView {

    private final SurfaceHolder surfaceHolder;
    private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    private List<Point> pointsList = new ArrayList<Point>();

    public DrawingView(Context context) {
        super(context);
        surfaceHolder = getHolder();
        paint.setColor(Color.WHITE);
        paint.setStyle(Style.FILL);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (surfaceHolder.getSurface().isValid()) {

                // Add current touch position to the list of points
                pointsList.add(new Point((int)event.getX(), (int)event.getY()));

                // Get canvas from surface
                Canvas canvas = surfaceHolder.lockCanvas();

                // Clear screen
                canvas.drawColor(Color.BLACK);

                // Iterate on the list
                for(int i=0; i<pointsList.size(); i++) {
                    Point current = pointsList.get(i);

                    // Draw points
                    canvas.drawCircle(current.x, current.y, 10, paint);

                    // Draw line with next point (if it exists)
                    if(i + 1 < pointsList.size()) {
                        Point next = pointsList.get(i+1);
                        canvas.drawLine(current.x, current.y, next.x, next.y, paint);
                    }
                }

                // Release canvas
                surfaceHolder.unlockCanvasAndPost(canvas);
            }
        }
        return false;
    }

}
于 2012-11-09T12:23:11.963 に答える