pentagon graph

Marius44

Board Regular
Joined
Aug 30, 2016
Messages
69
Hello to all


How do I put a regular pentagon in an excel graph knowing the length of the side and the width of the angle (108 °) formed on two sides.

Thanks in advance. Hello,
Mario

PS. I excuse for my english
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Thank you for your prompt reply

But i have to built a Chart whit VBA not with the tool

Bye,
Marius
 
Upvote 0
Thank you for your prompt reply

But i have to built a Chart whit VBA not with the tool

Bye,
Marius
Hello Marius, ice to meet you.

I assume you'll need to calculate coordinates for pentagon, but also hexagon, heptagon, octagon and so on.
For this reason let me suggest the following Function:
Code:
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
Then in your worksheet you shall use the following formula:
Code:
=MultiGon(SideLength, NumberOfSides)
You need to insert it as an array formula in a grid o 2 columns * NumberOfSides

For example, for a Pentagon:
Code:
=MultiGon(SideLength, 5)
on an array of 5 rows and 2 columns

Bye
 
  • Like
Reactions: shg
Upvote 0
5095
6095
46.9185.49
63.0985.49
5579.61
these are the coordinates
for a pentagon of side = 10 units
plot a scatter chart

<colgroup><col width="64" span="5" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
Thanks to both


@oldbrever
Your suggestion in a scatter-graph shows me a staircase!

@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
Code:
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

Thank you very much.
Ciao,
Mario
 
Upvote 0
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
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).
If you need one additional coordinate (to close the graph) my function become
Code:
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

If you wish to use it in another macro, just use, for example:
Code:
Range("K1:L12") = MultiGon(Range("J1"), Range("J2"))
You correctly realized that if the range (K1:L12, in this case) is longer than the returned coordinates, the extra positions will be filled by error #N/A, that makes them invisible for the graph.

Ciao ;)
 
Upvote 0
Ok, Ok is syntactically incorrect (you know me well and know that I'm not very orthodox) but FUNCTIONS (I can assure you). I still pay due attention and correct it.


Rather, if I do not ask too much, I would like a straight to place the Chart in the fourth upper right at the Cartesian plane and not with the intersection of the axes at the center of the polygon.
What should I correct? Thanks again.
Hello,
Marius
 
Upvote 0
Hi 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.
 
Last edited:
Upvote 0
Hi 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.
Mario, please check your email box
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,392
Members
449,445
Latest member
JJFabEngineering

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top