【问题标题】:Draw Cone Go JS base on angle and degree根据角度和度数绘制 Cone Go JS
【发布时间】:2023-01-14 20:48:54
【问题描述】:

关于如何根据角度和度数动态地进行此操作的任何想法?

我有这个用于绘制一条简单的贝塞尔曲线。

 var KAPPA = 4 * ((Math.sqrt(2) - 1) / 3);
    go.Shape.defineFigureGenerator("Cone3", function(shape, w, h) {
      var geo = new go.Geometry();
      var cpxOffset = KAPPA * .5;
      var cpyOffset = KAPPA * .1;
      var fig = new go.PathFigure(0, .9 * h, true);
      geo.add(fig);
    
      fig.add(new go.PathSegment(go.PathSegment.Line, .5 * w, 0));
      fig.add(new go.PathSegment(go.PathSegment.Line, w, .9 * h));
      fig.add(new go.PathSegment(go.PathSegment.Bezier, .5 * w, h, w, (.9 + cpyOffset) * h,
        (.5 + cpxOffset) * w, h));
      fig.add(new go.PathSegment(go.PathSegment.Bezier, 0, .9 * h, (.5 - cpxOffset) * w, h,
        0, (.9 + cpyOffset) * h).close());
      geo.spot1 = new go.Spot(.25, .5);
      geo.spot2 = new go.Spot(.180, .97);
      return geo;
    });

【问题讨论】:

    标签: gojs


    【解决方案1】:

    此示例中给出了一种解决方案:https://gojs.net/latest/extensions/SectorReshaping.html

        function makeSector(data) {  // Geometry converter for the node's "LAMP" Shape
          var radius = SectorReshapingTool.getRadius(data);
          var angle = SectorReshapingTool.getAngle(data);
          var sweep = SectorReshapingTool.getSweep(data);
          var start = new go.Point(radius, 0).rotate(angle);
          // this is much more efficient than calling go.GraphObject.make:
          var geo = new go.Geometry()
            .add(new go.PathFigure(radius + start.x, radius + start.y)  // start point
              .add(new go.PathSegment(go.PathSegment.Arc,
                angle, sweep,  // angles
                radius, radius,  // center
                radius, radius))  // radius
              .add(new go.PathSegment(go.PathSegment.Line, radius, radius).close()))
            .add(new go.PathFigure(0, 0))  // make sure the Geometry always includes the whole circle
            .add(new go.PathFigure(2 * radius, 2 * radius));  // even if only a small sector is "lit"
          return geo;
        }
    

    不过,该示例的目的是演示一种允许用户以交互方式修改此类形状的工具。我不知道你是否需要这样的功能。

    【讨论】:

      猜你喜欢
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多