2012-11-09 28 views
1

有沒有人在繪圖對象上有頂點經驗?多邊形並獲得其表面和周長。屏幕上的Android繪圖對象和獲取幾何圖形數據

使用頂點或類似於https://play.google.com/store/apps/details?id=de.hms.xconstruction的座標手動繪製幾何圖形,然後形成形狀。我需要獲得這些封閉形狀的表面。

網上有沒有可用的例子?

在此先感謝。

+0

聽起來更像是一個數學問題,對嗎? – fiddler

+0

是的,但數學來得晚,首先我必須通過某種方法以某種方式識別形狀。我只需要一個示例來定位並瞭解如何解決這樣的問題。這些步驟肯定是通過一些ontouchScreen方法輸入幾何圖形,然後在完成形狀分析並進行一些數學運算以獲得曲面之後。 – user1616685

回答

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; 
    } 

} 
+0

謝謝!在此期間,我找到了數學: user1616685