• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Create an isosceles triangle from the centre point of a circle

Daics

New Member
Hi.
Is there a way to create an isosceles triangle ( a "pie section") radiating outwards from the centre of a circle and using the centre of the circle as the apex of the triangle? The angle at the apex of the triangle will vary according to the number of triangles needed - just as pie sections do.
I am not keen on using the excel library and manipulating "pie-type" images.

My code, at present, (albeit rather clumsy) describes the circle and the centre point along with a variable number of "spokes" which are numbered at the circumference of the main circle.
After creating the code to insert the "spokes" I figure I would rather triangles (like pie sections) so I can colour fill the interior of each triangle.
Any help will be greatly appreciated.

>>> use code - tags <<<
Code:
Xpt = 10 * 18.75 ' left hand pt on ws
Ypt = 10 * 9.75 ' tp point on ws
w = 10 * 18.75
ht = 10 * 18.75

Set ccl = Sheets("Home").Shapes.AddShape(msoShapeOval, Xpt, Ypt, w, ht)
With ccl
    .Fill.ForeColor.RGB = dta_3_clr
    .Line.Weight = 2
End With

'CALCULATE CENTRE POINT OF CIRCLE
cptx = Xpt + w / 2 - 5
cpty = Ypt + ht / 2 - 5

'CREATE CENTRE POINT CIRCLE
Set ring = Sheets("Home").Shapes.AddShape(msoShapeOval, cptx, cpty, 10, 10)
With ring
    .Name = "ccl_c"
    .Fill.ForeColor.RGB = mn_clr
    .Line.Visible = msoFalse
End With

'OUTSIDE "TAGS" and "SPOKES"
shp_colr = lge_rng
st = 1
nd = 12
zz = 20
For xxx = st To nd
    d = ht / 2
    n = xxx / nd * 360 - 90
    rd = WorksheetFunction.Radians(n)
    x = cptx + d * Cos(rd)
    y = cpty + d * Sin(rd)
    Set ring = h.Shapes.AddShape(msoShapeOval, x, y, zz, zz)
    With ring
        .Name = "Ring_" & xxx
        .Fill.ForeColor.RGB = mn_clr
        .Line.Visible = msoFalse
        .TextFrame2.TextRange.Font.Fill.ForeColor.RGB = wht_clr
        .TextFrame2.TextRange.Characters.Font.Name = "Lucida Sans"
        .TextFrame2.TextRange.Characters.Font.Size = 5
        .TextFrame2.VerticalAnchor = msoAnchorMiddle
        .TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignCenter
        .TextFrame2.TextRange.Characters.Text = xxx
        ln1 = x + zz / 2
        ln2 = y + zz / 2
        Set Ln_1 = h.Shapes.AddConnector(msoConnectorStraight, cptx + zz / 2, cpty + zz / 2, ln1, ln2)
        With Ln_1
            .Line.ForeColor.RGB = mn_clr
        End With
        Set Ln_2 = h.Shapes.AddConnector(msoConnectorStraight, cptx + zz / 2, cpty + zz / 2, ln1, ln2)
        With Ln_2
            .Line.ForeColor.RGB = mn_clr
        End With
       
    End With

Regards,

Daics
 
Last edited by a moderator:
Daics
Your Is there a way to create ... An answer is yes...
You sent a partial code.
You could upload here Your Excel-file with expected sample result.
 
Thank you for the response.
The file is now attached.
 

Attachments

  • DEMO_FILE_61120_UPLOAD.zip
    429.6 KB · Views: 2
Daics
Your Is there a way to create ... still 'yes'.

Before start to thinking more, verifying..
Did You mean something like below sample?
isosceles triangle from the centre point of a circle
( except those triangles positions should slide to correct position )
Excel has ready shapes, which You could use Yourself.
Screenshot 2020-11-06 at 09.33.05.png
You could modify Your code Yourself.
If I would write that code, it would be ... different ... than Yours.
Ps. If You save that file as .xlsb then its size is ~231kB.
 
Thank you.
Your verification image is on track.
I would like to create these "slices" dynamically. This includes sizing of width and length so I would appreciate your coding input.
It will be a great learning experience for me.
 
Daics
Dynamic ... hmm? ... with s_max, You can give number (now 10) of 'slices'.
Below sample code creates 'slices' to home-sheet.
You can add Your colors as well as other Your features there.
Code:
Sub Do_It()
    With Sheets("Home")
        For s = .Shapes.Count To 1 Step -1
            If Left(.Shapes(s).Name, 2) = "S_" Then .Shapes(s).Delete
        Next s
        P = WorksheetFunction.Pi
        s_max = 10
        x0 = 300
        y0 = 300
        d0 = 300
        w0 = Tan(P / s_max) * d0
        For s = 1 To s_max
            a = s / s_max * 360
            With .Shapes.AddShape(msoShapeIsoscelesTriangle, x0 - w0 / 2 + d0 / 2, y0, w0, d0)
                .Name = "S_" & s
                .IncrementRotation a + 180
                .ScaleHeight 0.5, msoFalse, msoScaleFromBottomRight
            End With
        Next s
    End With
End Sub
 
Thank you for your help vietm.
The code works perfectly.
Now I just have too comes to grips with how it all works.
Very much appreciated.
 
I may have clarifying/further question(s) as I go through the code.
Am I able to ask , as an add on to this query, or do I create a new post?
Thanks
 
I am now trying to create the isosceles triangles with variable lengths.

I have tried but I can't quite figure out how to

alter the code in order to do this.

71940
 
Thank you again, vietm.
The attached file builds on your interpretation.
The orange shapes approximate what I am ultimately trying to achieve.
I greatly appreciate your coding solutions.
 

Attachments

  • DEMO_FILE_81120_UPLOAD.xlsb
    232.1 KB · Views: 2
Daics
Based You the original layout ... that's different!
Seems that You have done it manually.
Do You want to have there spaces between slices or what?
There could be many many possibilities ...
What would be Your real needs?
Here - sample #3 ... press that [ Show3 ]-button.
( ... press again it to stop )
 

Attachments

  • DEMO_FILE_81120_UPLOAD.xlsb
    264.6 KB · Views: 1
Yes, it is quite different to my starting point.
Because my coding is at a limited level, I thought if I could create "spokes" radiating from the centre of a circle I could gradually alter that code to get to the final image which was in the last file I attached.
But in the process of creating the "spokes" I realised I could not apply colour to each segment.
So then I sought help to create the isosceles triangles where you provided the exquisite code.
I then thought I would try to work around the code you sent to alter the length of the triangles and also create a gap between each.
My attempts to work around the code produced some unintended, attractive patterns but not what I needed.
So, in total desperation I attached the file of orange triangles - my intended goal that I thought I could achieve.

The task...
These triangles will dynamically change in number and length; a circular representation of a bar graph - i.e. the spokes or pie segments meet at the centre point of the circle.
The space between each triangle is purely aesthetic.
I do hope you can help code wise here.
My sincere thanks.
 
Daics
Did You pressed that [ Show3 ] with previous version... ?
This [ Show4 ]-version would have Your purely aesthetic spaces between each triangle.
Ouch ... I left those my colors ... but You can modify it too.
Test it ...
 

Attachments

  • DEMO_FILE_81120_UPLOAD.xlsb
    271 KB · Views: 4
Thank you.
I am in bed today, just accessing by phone.
Haven't been able to view the attachments.
I can't wait to see.
Again, thank you so much.
 
@Daics

Can I ask what the application of this is ?

If it is for displaying wind roses, there are better solutions already around
 
A potential client showed me an image which he wanted me to re-create but I had never seen it before.
My first reaction was, with my current skill level, it would be impossible - a bit like creating a fractal!
I could not deliver for him so I did some research and found sunburst images.
I do not use the excel library of graphical inserts so I tried to create my own via code - using some pretty basic trig.
In this process, quite by accident, I created an approximation (not a very good one) of a wind rose.
As I am relatively naive with images like these, I am very interested in what is around.
Any guidance would be appreciated.
 
Thank you.
In bed again so will be a while before I view it with some internal clarity.
I am very appreciative of your help
 
Daics
With my sample, there could set each 'slices' width, height and color based data.
You had there numbers around Your the first snapshot - do those needs?
Screenshot 2020-11-09 at 20.50.31.png
 
Hi vletm
This is amazing
I like the graphic nature of the previous post.
In relation to the question about numbers...
Yes, they are important for me.
I tried to locate the numbers at the outside extremity of each triangle.
The code you have provided is, once again, exquisite and it will take me a while to understand it.
Thank you again
 
Back
Top