Hello Marius, ice to meet you.Thank you for your prompt reply
But i have to built a Chart whit VBA not with the tool
Bye,
Marius
Function MultiGon(ByVal LLen As Single, ByVal NLati As Long) As Variant
'see https://www.mrexcel.com/forum/excel-questions/1022782-pentagon-graph.html
Dim rArr(), Alpha As Double, Lato As Double, Ragg As Double, I As Long
'
ReDim rArr(1 To NLati, 1 To 2)
Alpha = 2 * Application.WorksheetFunction.Pi / NLati
Ragg = LLen / 2 / Sin(Alpha / 2)
For I = 1 To NLati
rArr(I, 1) = Ragg * Sin(Alpha * I)
rArr(I, 2) = Ragg * Cos(Alpha * I)
Next I
MultiGon = rArr
End Function
=MultiGon(SideLength, NumberOfSides)
=MultiGon(SideLength, 5)
Sub pentagono()
LLen = Range("J1"): NLati = Range("J2")
Range("K1:L12").ClearContents
Call Pentagon(LLen, NLati)
End Sub
Function Pentagon(ByVal LLen As Single, ByVal NLati As Long) As Variant
'see https://www.mrexcel.com/forum/excel-questions/1022782-pentagon-graph.html
Dim rArr(), Alpha As Double, Lato As Double, Ragg As Double, I As Long
'
LLen = 10
ReDim rArr(1 To NLati, 1 To 2)
Alpha = 2 * Application.WorksheetFunction.Pi / NLati
Ragg = LLen / 2 / Sin(Alpha / 2)
For I = 1 To NLati
rArr(I, 1) = Ragg * Sin(Alpha * I)
rArr(I, 2) = Ragg * Cos(Alpha * I)
Cells(I, 11) = rArr(I, 1)
Cells(I, 12) = rArr(I, 2)
Next I
Cells(I, 11) = rArr(1, 1)
Cells(I, 12) = rArr(1, 2)
'MultiGon = rArr
End Function
That correction is syntactly wrong and cannot work (you cannot use a Function to modify cells, eccept the caller ones); nor a Function need to be "Called" from another routine; and finally that would kill one of the objective of my Function (generate any regular poligon).Thanks to both
@Anthony47
Your suggestion would be PERFECT if it did not have a small defect: it does not close the figure as it lacks the last segment.
I've "adapted" my needs to your macro as shown below
[. . .]
Thank you very much.
Ciao,
Mario
Function MultiGon(ByVal LLen As Single, ByVal NLati As Long) As Variant
'see https://www.mrexcel.com/forum/excel-questions/1022782-pentagon-graph.html
Dim rArr(), Alpha As Double, Lato As Double, Ragg As Double, I As Long
'
ReDim rArr(1 To NLati + 1, 1 To 2)
Alpha = 2 * Application.WorksheetFunction.Pi / NLati
Ragg = LLen / 2 / Sin(Alpha / 2)
For I = 1 To NLati + 1
rArr(I, 1) = Ragg * Sin(Alpha * I)
rArr(I, 2) = Ragg * Cos(Alpha * I)
Next I
MultiGon = rArr
End Function
Range("K1:L12") = MultiGon(Range("J1"), Range("J2"))
Mario, please check your email boxHi Anthony
Unfortunately, your last suggestion does not give me the hoped-for result. The mArr array is empty.
I do not understand why.
Byebye,
Marius
PS - my error of script. Excuse me.