为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 73 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信