Forgot password?

Create an account!

Forum

« back

RhinoScript – Polygon by edge

Messages

Please log in to write a message.

  • 12. mrreds (Aug 19, 2011 00.17):

    Thanks a lot Damon!!
    Your code was very helpful for me and your math was not wrong (I dusted my old geometry books).
    It was only a couple of brackets and was inverted the math between inner and outer circle.
    The rest was perfect!
    Follows my code with comments:

    Option Explicit
    'Script written by Damon Sidel
    'Script updated by MrReds
    'Script copyrighted by Damon Sidel
    'Script version Tuesday, August 16, 2011 10:09:17 AM

    Call PolygonInscribed()
    Sub PolygonInscribed()

            'Get number of sides from the user
            Dim intSides : intSides = Rhino.GetInteger("How many sides?",8,3)
            If IsNull(intSides) Then Exit Sub
           
            'Get radius of inner circle from user
            Dim dblLength : dblLength = Rhino.GetReal("Length of a side?",12.0)
            If IsNull(dblLength) Then Exit Sub
           
            'Calculate radius of outer circle
            Dim pi : pi = Rhino.Pi()
           
            'Ledisnomad
            'Dim dblORadius : dblORadius = dblLength / 2*Tan(pi/intSides)
            'Dim dblIRadius : dblIRadius = dblLength / 2*Sin(pi/intSides)
           
           
            'MrReds
            Dim dblIRadius : dblIRadius = dblLength / (2*Tan(pi/intSides))
            Dim dblORadius : dblORadius = dblLength / (2*Sin(pi/intSides))
           
            Call Rhino.Print("r = " & CStr(dblIRadius))

            Dim arrPlane : arrPlane = Rhino.PlaneFromNormal(Array(0,0,0),Array(0,0,1))
            Dim strICircle : strICircle = Rhino.AddCircle(arrPlane,dblIRadius)
            Dim strOCircle : strOCircle = Rhino.AddCircle(arrPlane,dblORadius)

            Dim arrDivPts : arrDivPts = Rhino.DivideCurve(strOCircle,intSides)
           
            'Draw the polygon
            Dim i
            For i=0 To intSides-2
                   
                    Call Rhino.AddLine(arrDivPts(i),arrDivPts(i+1))
                   
            Next
           
            'Draw the last side
            Call Rhino.AddLine(arrDivPts(intSides-1),arrDivPts(0))
           
            'Call Rhino.DeleteObject(strOCircle)
           
    End Sub

  • 11. ledisnomad (Aug 17, 2011 20.04):

    You're English is fine. The more background information you give, the easier it is to develop a script. I've made another attempt, but I think my math is wrong in these two lines, where dbleORadius it the radius of the circumscribed circle and dbleIRadius is the radius of the inscribed circle:

           
    Dim dblORadius : dblORadius = dblLength / 2*Tan(pi/intSides)
    Dim dblIRadius : dblIRadius = dblLength / 2*Sin(pi/intSides)

    Here's the whole thing:

    Option Explicit
    'Script written by Damon Sidel
    'Script copyrighted by Damon Sidel
    'Script version Tuesday, August 16, 2011 10:09:17 AM

    Call PolygonInscribed()
    Sub PolygonInscribed()

            'Get number of sides from the user
            Dim intSides : intSides = Rhino.GetInteger("How many sides?",8,3)
            If IsNull(intSides) Then Exit Sub
           
            'Get radius of inner circle from user
            Dim dblLength : dblLength = Rhino.GetReal("Length of a side?",12.0)
            If IsNull(dblLength) Then Exit Sub
           
            'Calculate radius of outer circle
            Dim pi : pi = Rhino.Pi()
            Dim dblORadius : dblORadius = dblLength / 2*Tan(pi/intSides)
            Dim dblIRadius : dblIRadius = dblLength / 2*Sin(pi/intSides)
            Call Rhino.Print("r = " & CStr(dblIRadius))

            Dim arrPlane : arrPlane = Rhino.PlaneFromNormal(Array(0,0,0),Array(0,0,1))
            Dim strICircle : strICircle = Rhino.AddCircle(arrPlane,dblIRadius)
            Dim strOCircle : strOCircle = Rhino.AddCircle(arrPlane,dblORadius)

            Dim arrDivPts : arrDivPts = Rhino.DivideCurve(strOCircle,intSides)
           
            'Draw the polygon
            Dim i
            For i=0 To intSides-2
                   
                    Call Rhino.AddLine(arrDivPts(i),arrDivPts(i+1))
                   
            Next
           
            'Draw the last side
            Call Rhino.AddLine(arrDivPts(intSides-1),arrDivPts(0))
           
            'Call Rhino.DeleteObject(strOCircle)
           
    End Sub
  • 10. mrreds (Aug 16, 2011 23.44):

    Yes Ledisnomad, it should be a part of a larger script. The polygon represents the bases of n (the sides) radial panels. So I want to calculate the minimum circle to avoid that the panels cross themselves (I hope to have explain clear).
    You are right when you say me to be more specific but my english is not too good.

  • 9. mrreds (Aug 16, 2011 23.33):

    Thanks a lot. Your script runs fine.
    But my need is to draw first the polygon by passing number of sides and lenght of sides to built the circle. The circle is the unknown and the purpose of the script.

    Thanks in advance for your help.

  • 8. ledisnomad (Aug 16, 2011 23.29):

    mmreds.
    I understand. Next time, you should be more specific. What you are describing now is a different problem, although not so different that the approach I took is invalid.

    To clarify, you want the user to input:
    1. number of sides, n
    2. length of a side, l
    Then the script should draw:
    a. the polygon with n sides
    b. a circle inscribed within the polygon

    Is that correct? How many times are you going to do this operation? Is it part of a larger script? It's pretty easy to draw what you are asking and may be faster than writing/waiting for a script.

  • 7. mrreds (Aug 16, 2011 23.21):

    Thanks a lot. Your script runs fine.
    But my need is to draw first the polygon by passing number of sides and lenght of sides to built the circle. The circle is the unknown and the purpose of the script.

    Thanks in advance for your help.

  • 6. ledisnomad (Aug 16, 2011 17.29):

    Here you go, mmreds. This should do what you want. You can add a

    Call Rhino.DeleteObject(strCircle)

    at the end of the script if you don't want to keep the circumscribing circle.

    Option Explicit
    'Script written by Damon Sidel
    'Script copyrighted by Damon Sidel
    'Script version Tuesday, August 16, 2011 10:09:17 AM

    Call PolygonInscribed()
    Sub PolygonInscribed()

            'Get number of sides from the user
            Dim intSides : intSides = Rhino.GetInteger("How many sides?",8,3)
            If IsNull(intSides) Then Exit Sub
           
            'Get radius of inner circle from user
            Dim dblIRadius : dblIRadius = Rhino.GetReal("Radius of inscribed circle",48.0)
            If IsNull(dblIRadius) Then Exit Sub
           
            'Calculate radius of outer circle
            Dim pi : pi = Rhino.Pi()
            Dim dblAngle : dblAngle = 2*pi/intSides
            Dim dblORadius : dblORadius = dblIRadius/Cos(dblAngle/2)
                   
            Dim arrPlane : arrPlane = Rhino.PlaneFromNormal(Array(0,0,0),Array(0,0,1))
            'Draw inner circle     
            Call Rhino.AddCircle(arrPlane,dblIRadius)
            'Draw outer circle and divide it into number of sides
            Dim strCircle : strCircle = Rhino.AddCircle(arrPlane,dblORadius)
            Dim arrDivPts : arrDivPts = Rhino.DivideCurve(strCircle,intSides)
           
            'Draw the polygon
            Dim i
            For i=0 To intSides-2
                   
                    Call Rhino.AddLine(arrDivPts(i),arrDivPts(i+1))
                   
            Next
           
            'Draw the last side
            Call Rhino.AddLine(arrDivPts(intSides-1),arrDivPts(0))
           
    End Sub
  • 5. ledisnomad (Aug 16, 2011 16.22):

    On second thought, we could always calculate the radius of the circumscribing circle from an inscribing circle... I'll see what I come up with.

  • 4. ledisnomad (Aug 16, 2011 15.49):

    You could draw the circle first and divide it by the number of sides you want, then draw the lines using the divisions. Here's a basic script that creates a circumscribed circle (it was faster to figure out for me than the inscribed circle... but I'm sure that is not too hard, either).

    Option Explicit
    'Script written by Damon Sidel
    'Script copyrighted by Damon Sidel
    'Script version Tuesday, August 16, 2011 9:23:05 AM

    Call Polygon()
    Sub Polygon()

            Dim intSides : intSides = Rhino.GetInteger("How many sides?",8,3)
            If IsNull(intSides) Then Exit Sub
           
            Dim dblRadius : dblRadius = Rhino.GetReal("Radius of circumscribed circle",48.0)
            If IsNull(dblRadius) Then Exit Sub
           
            Dim arrPlane : arrPlane = Rhino.PlaneFromNormal(Array(0,0,0),Array(0,0,1))
            Dim strCircle : strCircle = Rhino.AddCircle(arrPlane,dblRadius)
            Dim arrDivPts : arrDivPts = Rhino.DivideCurve(strCircle,intSides)
           
            Dim i
            For i=0 To intSides-2
                   
                    Call Rhino.AddLine(arrDivPts(i),arrDivPts(i+1))
                   
            Next
           
            Call Rhino.AddLine(arrDivPts(intSides-1),arrDivPts(0))
           
           
    End Sub

    If you were to do it with an inscribed circle, I think you'd have to create lines tangent to the division points and just do the math to figure out their length. If this script doesn't do what you need it to do and you need the inscribed circle, let me know and we can figure it out together.

  • 3. mrreds (Aug 16, 2011 12.50):

    Thanks arrow but I was not too clear in my explanation.
    I want to draw a polygon via rhinoscript. The object Rhino can handle the rhino _polygon command?
    The only way I found is to draw n lines and rotate them by 360/n on his end every line.

    Andrea

  • 2. Arrow.111 (Aug 16, 2011 02.42):

    hi,
    rhino has its own icon and command to create poligons
    command:_Polygon
    question :Center of inscribed polygon ( NumSides=5 Circumscribed Edge Star Vertical AroundCurve )
    Do you need somting more?

    Rob

  • 1. mrreds (Aug 15, 2011 16.42):

    Hi all,
    I'm quite new in scritping and I'm going mad to solve this problem.
    I want to draw a polygon with a specified number of sides "_Polygon by Edge"
    Then I want to draw the circle inscribed.
    What's the way to do it?

    Thanks
    Andrea

Recommend

Why are these buttons gray?