2015-05-21 104 views
0

我試圖繪製多邊形與AndroidPlot庫。
我成功地繪製四點,但它僅消耗3多邊形的邊。 (它不關閉多邊形)
應填充多邊形。我怎樣才能做到這一點?如何用androidPlot庫繪製多邊形?

謝謝!

編輯:

我先畫一個點,然後多邊形,因爲我有顯示,如果該點將在多邊形內部。

private XYPlot plot; 
plot = (XYPlot) findViewById(R.id.graph); 

seriesPointFormat = new LineAndPointFormatter(
        null,     // line color 
        Color.rgb(5, 100, 150),     // point color 
        null,         // fill color 
        new PointLabelFormatter()); 

      float[] xTol = intent.getExtras().getFloatArray("tolerancesX"); 
      float[] yTol = intent.getExtras().getFloatArray("tolerancesY"); 

      Float[] xTolerances = new Float[xTol.length]; 
      Float[] yTolerances = new Float[yTol.length]; 

     for(int i = 0; i< xTol.length; i++) 
      xTolerances[i] = xTol[i]; 

     for(int i = 0; i< yTol.length; i++) 
      yTolerances[i] = yTol[i]; 

      //Example 
      x=0.35f; 
      y=0.65f; 
      //Turn the above arrays into XYSeries': 
      XYSeries seriesPoint = new SimpleXYSeries(
        Arrays.asList(x),  
        Arrays.asList(y), 
        "point");       // Set the display title of the series 

      plot.getGraphWidget().setDomainValueFormat(new DecimalFormat("##.###")); 

      // add a new series' to the xyplot: 
      plot.addSeries(seriesPoint, seriesPointFormat); 

      XYSeries seriesPolygon = new SimpleXYSeries(
        Arrays.asList(xTolerances), 
        Arrays.asList(yTolerances), 
        "Polygon"); 

      LineAndPointFormatter seriesPolygonFormat = new LineAndPointFormatter(
        Color.rgb(500, 0, 0), // line color 
        Color.rgb(500, 100, 0), // point color 
        null, 
        new PointLabelFormatter()); 

      seriesPolygonFormat.getLinePaint().setStrokeWidth(2); 

      plot.addSeries(seriesPolygon, seriesPolygonFormat); 
+0

爲了幫助別人理解你的問題,請張貼的代碼樣本,所有日誌(例如logcat的)或某物的輸出,表現出[最小的,完整的,和可覈查的示例](http://stackoverflow.com/幫助/ mcve)你的問題。 –

回答

0

答案是顯而易見的,愚蠢的我......(捂臉)

你只需要在數組的末尾添加的第一個點。

 Float[] xTolerances = new Float[xTol.length+1]; 
     Float[] yTolerances = new Float[yTol.length+1]; 
     for(int i = 0; i< xTol.length; i++) 
      xTolerances[i] = xTol[i]; 
     //add here the first x coordinate at the end of the array 
     xTolerances[xTol.length] = xTol[0]; 

     for(int i = 0; i< yTol.length; i++) 
      yTolerances[i] = yTol[i]; 
     //add here the first x coordinate at the end of the array 
     yTolerances[yTol.length] = yTol[0]; 

並填補多邊形:

LineAndPointFormatter seriesPolygonFormat = new LineAndPointFormatter(
       Color.rgb(500, 0, 0), // line color 
       Color.rgb(500, 100, 100), // point color 
       Color.argb(50, 200, 0, 0), //fill color with alpha, to make the fill transparent 
       new PointLabelFormatter()); 

我不會取消的問題,也許將是有用的人。