Creating Triangle

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

  • 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

  • Geometry 6th grade of secondary school

    Sub CreateTriangle_3_5_6cm()
    Dim s As Shape, s1 As Shape, s2 As Shape, cpR As CrossPoints
    Dim a As Double, b As Double, c As Double, X As Double, Y As Double

    ActiveDocument.Unit = cdrMillimeter
    a = 60
    b = 50
    c = 30

    Set s = ActiveLayer.CreateLineSegment(50, 50, 50 + a, 50)
    Set s1 = ActiveLayer.CreateEllipse2(100, 100, b, b)
    s1.ConvertToCurves
    Set s2 = ActiveLayer.CreateEllipse2(100, 100, c, c)
    s2.ConvertToCurves

    s1.CenterX = s.Curve.Nodes(1).PositionX
    s1.CenterY = s.Curve.Nodes(1).PositionY
    s2.CenterX = s.Curve.Nodes(2).PositionX
    s2.CenterY = s.Curve.Nodes(2).PositionY

    Set cpR = s1.Curve.SubPaths(1).GetIntersections(s2.Curve.SubPaths(1), cdrAbsoluteSegmentOffset)
    X = cpR.Item(2).PositionX
    Y = cpR.Item(2).PositionY
    s1.Delete
    s2.Delete

    Set s1 = ActiveLayer.CreateLineSegment(s.Curve.Nodes(1).PositionX, s.Curve.Nodes(1).PositionY, X, Y)
    Set s2 = ActiveLayer.CreateLineSegment(s.Curve.Nodes(2).PositionX, s.Curve.Nodes(2).PositionY, X, Y)
    End Sub

    Get in touch if you need anything
    Best regards
    Taras