2015-05-21 3 views
0

Я пытаюсь нарисовать многоугольник с библиотекой AndroidPlot.
Я успешно рисую четыре очка, но он рисует только 3 стороны многоугольника. (он не закрывает многоугольник)
Полигон должен быть заполнен. Как я могу это достичь?Как нарисовать многоугольник с библиотекой androidPlot?

Спасибо!

Edit:

Я, во-первых, рисование точки и затем полигон, потому что я должен показать, если эта точка будет находиться внутри многоугольника.

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/ help/mcve) вашей проблемы. –

ответ

0

Ответ очевиден, глупо мне ... (Facepalm)

Вы просто должны добавить первую точку в конце массива.

 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()); 

Я не отменит этот вопрос, возможно, будет полезным для кого-то.

Смежные вопросы