📄 pieplot3d.java
字号:
side.intersect(back); g2.setPaint(paint); g2.fill(side); g2.setPaint(outlinePaint); g2.draw(side); } } else { // starts at the back, wraps around front, and finishes at back again Area side1 = new Area( new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight() ) ); side1.intersect(back); Area side2 = new Area( new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight() ) ); side2.intersect(back); g2.setPaint(paint); if (drawBack) { g2.fill(side1); g2.fill(side2); } if (drawFront) { g2.fill(front); } g2.setPaint(outlinePaint); if (drawBack) { g2.draw(side1); g2.draw(side2); } if (drawFront) { g2.draw(front); } } } else { // starts at back, finishes at front (CLOCKWISE) if (drawBack) { Area side1 = new Area( new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight() ) ); side1.intersect(back); g2.setPaint(paint); g2.fill(side1); g2.setPaint(outlinePaint); g2.draw(side1); } if (drawFront) { Area side2 = new Area( new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getEndPoint().getX(), plotArea.getHeight() ) ); side2.intersect(front); g2.setPaint(paint); g2.fill(side2); g2.setPaint(outlinePaint); g2.draw(side2); } } } } else if (extent > 0.0) { // the pie sections are arranged ANTICLOCKWISE if (isAngleAtFront(start)) { // segment starts at the front if (!isAngleAtBack(end)) { // and finishes at the front if (extent < 180.0) { // segment only occupies the front if (drawFront) { Area side = new Area( new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), arc.getEndPoint().getX() - arc.getStartPoint().getX(), plotArea.getHeight() ) ); side.intersect(front); g2.setPaint(paint); g2.fill(side); g2.setPaint(outlinePaint); g2.draw(side); } } else { // segments wraps right around the back... Area side1 = new Area( new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight() ) ); side1.intersect(front); Area side2 = new Area( new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight() ) ); side2.intersect(front); g2.setPaint(paint); if (drawFront) { g2.fill(side1); g2.fill(side2); } if (drawBack) { g2.fill(back); } g2.setPaint(outlinePaint); if (drawFront) { g2.draw(side1); g2.draw(side2); } if (drawBack) { g2.draw(back); } } } else { // segments starts at front and finishes at back... if (drawBack) { Area side2 = new Area( new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getEndPoint().getX(), plotArea.getHeight() ) ); side2.intersect(back); g2.setPaint(paint); g2.fill(side2); g2.setPaint(outlinePaint); g2.draw(side2); } if (drawFront) { Area side1 = new Area( new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight() ) ); side1.intersect(front); g2.setPaint(paint); g2.fill(side1); g2.setPaint(outlinePaint); g2.draw(side1); } } } else { // segment starts at back if (!isAngleAtFront(end)) { if (extent < 180.0) { // and finishes at back if (drawBack) { Area side = new Area( new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), arc.getStartPoint().getX() - arc.getEndPoint().getX(), plotArea.getHeight() ) ); side.intersect(back); g2.setPaint(paint); g2.fill(side); g2.setPaint(outlinePaint); g2.draw(side); } } else { // starts at back and wraps right around to the back again Area side1 = new Area( new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getX() - arc.getStartPoint().getX(), plotArea.getHeight() ) ); side1.intersect(back); Area side2 = new Area( new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getEndPoint().getX(), plotArea.getHeight() ) ); side2.intersect(back); g2.setPaint(paint); if (drawBack) { g2.fill(side1); g2.fill(side2); } if (drawFront) { g2.fill(front); } g2.setPaint(outlinePaint); if (drawBack) { g2.draw(side1); g2.draw(side2); } if (drawFront) { g2.draw(front); } } } else { // starts at the back and finishes at the front (wrapping the left side) if (drawBack) { Area side1 = new Area( new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getStartPoint().getX() - plotArea.getX(), plotArea.getHeight() ) ); side1.intersect(back); g2.setPaint(paint); g2.fill(side1); g2.setPaint(outlinePaint); g2.draw(side1); } if (drawFront) { Area side2 = new Area( new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight() ) ); side2.intersect(front); g2.setPaint(paint); g2.fill(side2); g2.setPaint(outlinePaint); g2.draw(side2); } } } } } /** * Returns a short string describing the type of plot. * * @return <i>Pie 3D Plot</i>. */ public String getPlotType () { return localizationResources.getString("Pie_3D_Plot"); } /** * A utility method that returns true if the angle represents a point at the front of the * 3D pie chart. 0 - 180 degrees is the back, 180 - 360 is the front. * * @param angle the angle. * * @return A boolean. */ private boolean isAngleAtFront(double angle) { return (Math.sin(Math.toRadians(angle)) < 0.0); } /** * A utility method that returns true if the angle represents a point at the back of the * 3D pie chart. 0 - 180 degrees is the back, 180 - 360 is the front. * * @param angle the angle. * * @return true if the angle is at the back of the pie. */ private boolean isAngleAtBack(double angle) { return (Math.sin(Math.toRadians(angle)) > 0.0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -