亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java Graphics 2d 避免折線扭曲角

Java Graphics 2d 避免折線扭曲角

哈士奇WWW 2023-11-10 16:02:38
我正在開發一個用于繪制地鐵地圖的圖形界面。一條線用圓圈表示,并用一條折線連接它們。您可以用鼠標拖動移動車站,當然它會實時更新顯示的地圖。我的問題是,當車站達到一定角度時,會出現折線變形,并且兩條線創建的角超出了車站圓圈顯示,我想知道是否有辦法避免這種情況。存在折線問題的應用程序的屏幕截圖這是我的折線繪制代碼//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));

斜接形成工件斜端或邊緣的表面,通過以一定角度切割兩塊并將它們裝配在一起來形成接頭。


查看完整回答
反對 回復 2023-11-10
  • 1 回答
  • 0 關注
  • 168 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號