5 Replies Latest reply on Jan 16, 2018 9:50 AM by Korbi Anis

    The circumscribed and the inscribed circle of 2D sketch

    Korbi Anis

      Hi friends , Are there someone who can help me to develop a VBA code to generate the circumscribed or the inscribed circle of 2D sketch.Best regards

          • Re: The circumscribed and the inscribed circle of 2D sketch
            Korbi Anis

            Hi dear Ivana .Thank you very much for your answer.However , it's not a vba code I think beacause I downlead the file but it's empty ! . thx

            • Re: The circumscribed and the inscribed circle of 2D sketch
              Korbi Anis

              In Matlab its exist a code that allows to calculate the center and the radius of the maximun circumscribed circle of a set of points ( these points refer to the 2D sketch for exemple ).These points are puted in excel file ( X,Y) .I tried maybe to do he link between vba excel and matlab to excute the results of matla code on VBA buu I found some problem with the results.Maybe there are something wrong in my code.

              This is the code VBA in excel



              Option Explicit



              Sub BuitlInFunction()





                  'Declaring the necessary variables.

                  Dim Xs()    As Variant

                  Dim Ys()    As Variant

                  Dim i       As Integer

                  Dim inpX    As String

                  Dim inpY    As String

                  Dim Matlab  As Object

                  Dim Result  As String

                  Dim temp    As String

                   Dim mFilePath   As String

                   Dim center As Double

                   Dim Radius As Double



                  'Get the input values.

                  Xs = Sheet1.Range("N5:N14")

                  Ys = Sheet1.Range("O5:O14")


                  'Transform the Xs array in the form 1,2,3...etc.

                  inpX = Xs(LBound(Xs), 1)

                  For i = LBound(Xs) + 1 To UBound(Xs) - 1

                      inpX = inpX & "," & Xs(i, 1)

                  Next i

                  inpX = inpX & "," & Xs(UBound(Xs), 1)


                  'Transform the Ys array in the form 1,2,3...etc.

                  inpY = Ys(LBound(Ys), 1)

                  For i = LBound(Ys) + 1 To UBound(Ys) - 1

                      inpY = inpY & "," & Ys(i, 1)

                  Next i

                  inpY = inpY & "," & Ys(UBound(Ys), 1)


                  'Set the MATLAB object (the COM server).

                  On Error Resume Next

                  Set Matlab = CreateObject("matlab.application")

                  'In the case of error inform the user and exit the macro.

                  If Err.Number <> 0 Then

                      MsgBox "Could not open MATLAB!", vbCritical, "MATLAB Error"

                      Exit Sub

                  End If

                  On Error GoTo 0


                    mFilePath = ("C:\Users\DOC\Desktop\Nouveau dossier\MinBoundSuite\minboundcircle.m")



                  'Load the m file in MATLAB.

                  Matlab.Execute ("cd('" & mFilePath & "\')")


                  'Execute the custom funciton (two outputs here, a and b).

                  Result = Matlab.Execute("[center,radius]=minboundcircle(" & inpX & "," & inpY & ")")


                  'Remove the unnecessary spaces from the string Result.

                  temp = WorksheetFunction.Substitute(WorksheetFunction.Substitute(Result, Chr(10), ""), " ", "")


                  'Find the output values in the string temp using Mid, Right, Len and Find functions.


                  'Display the function result to the user.

                  MsgBox "le centre et le rayon de cercle est :" & vbNewLine & "centre = " & center & vbNewLine & "Rayon= " & Radius, vbInformation, "MATLAB Result"



              End Sub



              please , I need your help .Thank you