Creating Triangle

Hello,
How to create triangle with sides 3, 5, 6 cm using CreatePolygon or one other way using VBA?
Greetings?

Parents
  • My C# Code

    [CgsAddInMacro]
    public Shape CreateTriangle(double a,double bdouble c)
    {
        double startX = 0;
        double startY = 0;
        Point A = corelApp.Math.CreatePoint(startX, startY);
        Point B = corelApp.Math.CreatePoint(startX + a, startY);
     
        Shape arcA = corelApp.ActiveVirtualLayer.CreateEllipse2(A.x, A.y, c);
        Shape arcB = corelApp.ActiveVirtualLayer.CreateEllipse2(B.x, B.y, b,b,180,0);
     
        CrossPoints cps = null;
     
        for (int i = 1; i <= arcB.DisplayCurve.Segments.Count; i++)
        {
            for (int j = 1; j <= arcA.DisplayCurve.Segments.Count; j++)
            {
                cps = arcB.DisplayCurve.Segments[i].GetIntersections(arcA.DisplayCurve.Segments[j]);
                if (cps != null && cps.Count > 0)
                    break;
            }
            if (cps != null && cps.Count > 0)
                break;
        }
     
        arcA.Delete();
        arcB.Delete();
     
        if (cps == null)
            throw new Exception("These measurements are not valid as a triangle");
     
        Point C = corelApp.Math.CreatePoint(cps[1].PositionX, cps[1].PositionY);
        PointRange pr = corelApp.Math.CreatePointRange();
        pr.AddPoint(A);
        pr.AddPoint(B);
        pr.AddPoint(C);
        pr.AddPoint(A);
        Curve curve = corelApp.CreateCurve(corelApp.ActiveDocument);
        curve.AppendSubpathFitToPoints(pr);
     
        Shape triangle = corelApp.ActiveLayer.CreateCurve(curve);
     
        triangle.RotationCenterX = (A.+ B.+ C.x) / 3;
        triangle.RotationCenterY = (A.+ B.+ C.y) / 3;
     
        return triangle;
    }

    VBA converted by ChatGPT

    Function CreateTriangle(ByVal SideA As Double, ByVal SideB As Double, ByVal SideC As Double) As Shape
    Dim startX As Double
    Dim startY As Double
    startX = 0
    startY = 0

    Dim A As Point
    Set A = ActiveDocument.Math.CreatePoint(startX, startY)

    Dim B As Point
    Set B = ActiveDocument.Math.CreatePoint(startX + SideA, startY)

    Dim arcA As Shape
    Set arcA = ActiveVirtualLayer.CreateEllipse2(A.x, A.y, SideC)

    Dim arcB As Shape
    Set arcB = ActiveVirtualLayer.CreateEllipse2(B.x, B.y, SideB, SideB, 180, 0)

    Dim cps As CrossPoints
    Set cps = Nothing

    Dim i As Integer
    Dim j As Integer
    For i = 1 To arcB.DisplayCurve.Segments.Count
    For j = 1 To arcA.DisplayCurve.Segments.Count
    Set cps = arcB.DisplayCurve.Segments(i).GetIntersections(arcA.DisplayCurve.Segments(j))
    If Not cps Is Nothing And cps.Count > 0 Then
    Exit For
    End If
    Next j
    If Not cps Is Nothing And cps.Count > 0 Then
    Exit For
    End If
    Next i

    arcA.Delete
    arcB.Delete

    If cps Is Nothing Then
    Err.Raise vbObjectError + 1, "CreateTriangle", "These measurements are not valid as a triangle"
    End If

    Dim C As Point
    Set C = ActiveDocument.Math.CreatePoint(cps(1).PositionX, cps(1).PositionY)

    Dim pr As PointRange
    Set pr = ActiveDocument.Math.CreatePointRange
    pr.AddPoint A
    pr.AddPoint B
    pr.AddPoint C
    pr.AddPoint A

    Dim curve As curve
    Set curve = CreateCurve
    curve.AppendSubpathFitToPoints pr

    Dim triangle As Shape
    Set triangle = ActiveLayer.CreateCurve(curve)

    triangle.RotationCenterX = (A.x + B.x + C.x) / 3
    triangle.RotationCenterY = (A.y + B.y + C.y) / 3

    Set CreateTriangle = triangle
    End Function

Reply Children
No Data