我正在開發一個用于繪制地鐵地圖的圖形界面。一條線用圓圈表示,并用一條折線連接它們。您可以用鼠標拖動移動車站,當然它會實時更新顯示的地圖。我的問題是,當車站達到一定角度時,會出現折線變形,并且兩條線創建的角超出了車站圓圈顯示,我想知道是否有辦法避免這種情況。存在折線問題的應用程序的屏幕截圖這是我的折線繪制代碼//x and y point array creation xPoints = new int[this.stationViews.size()]; yPoints = new int[this.stationViews.size()]; for (int i=0;i<this.stationViews.size();i++) { //fill arrays with the center point of circles representing stations xPoints[i] = this.stationViews.get(i).getStation().getPosX()-this.stationViews.size()/2; yPoints[i] = this.stationViews.get(i).getStation().getPosY()-this.stationViews.size(); } //setting color g2D.setColor(this.line.getColor()); //set stroke width relative to the zoom level int strokeWidth=5; if(!this.stationViews.isEmpty()) { if (this.stationViews.get(0).getStationSize()>14) { strokeWidth = this.stationViews.get(0).getStationSize()-13; }else { strokeWidth = 3; } } g2D.setStroke(new BasicStroke(strokeWidth)); //draw the polyline if (this.stationViews.size() >1) { g2D.drawPolyline(xPoints, yPoints, this.stationViews.size()); } //draw the station (g2D.drawCircle) for (StationView stationView : stationViews) { stationView.affiche(g2D,this.line.getColor()); }感謝您的幫助
1 回答

HUWWW
TA貢獻1874條經驗 獲得超12個贊
這就是所謂的斜接。您似乎默認使用 JOIN_MITER,即在末端尖銳地連接延長線,它可以指向遠離連接的小角度。
g2d.setStroke(new?BasicStroke(strokeWidth, ????BasicStroke.CAP_SQUARE,?BasicStroke.JOIN_ROUND,?5));
斜接形成工件斜端或邊緣的表面,通過以一定角度切割兩塊并將它們裝配在一起來形成接頭。
添加回答
舉報
0/150
提交
取消