Forgot password?

Create an account!

Forum

« back

RhinoScript – Create a Matrix

Messages

Please log in to write a message.

  • 8. alibek (Oct 06, 2016 16.59):

    Finally, I got it by using
    str = str & Matrix(k, l) command.
    If anybody will meet the same problem of printing matrix, you can do it as follows.
    Dim str, i,j
    str = "" (1.Create empty str)
    For i=0 To Ubound(smth)
    For j=0 To Ubound(smth)
    str = str & Matrix(i, j) (Creates first line of matrix)
    Next
    Rhino.Print str (Prints first line)
    str = "" (clears your line)
    Next

    So that the programm will print each row of matrix one by one, and finally the matrix will appear.

  • 7. alibek (Oct 05, 2016 20.46):

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version 4 ??????? 2016 ?. 23:40:16
    Call putpoints
    Sub PutPoints()
    Dim i,spoint,epoint,N,PNTS,pts
    ReDim PNTS(0)
    N = 0
    Const CurveConst = 4

    Dim line : line = Rhino.ObjectsByType(CurveConst)
    If IsNull(line) Then Rhino.Print("Nothing selected")
    If IsArray(line) Then
    For i=0 To Ubound(line)
    ReDim Preserve PNTS(N)
    PNTS(N) = Rhino.CurveStartPoint(line(i))
    N = N + 1
    ReDim Preserve PNTS(N)
    PNTS(N) = Rhino.CurveEndPoint(line(i))
    N = N + 1
    Next
    End If
    PNTS = Rhino.CullDuplicatePoints(PNTS)
    pts = Rhino.AddPoints(PNTS)
    For i=0 To ubound(PNTS)
    Rhino.addText i, PNTS(i), 1
    Next

    ReDim Lines(Ubound(line))
    Dim j,coord,dist,p
    For i=0 To ubound(line)
    Lines(i) = Array(Rhino.CurveStartPoint(line(i)), Rhino.CurveEndPoint(line(i)))
    Next
    Dim test_p
    Dim e:e = 1e-10
    Dim z
    z = Ubound(PNTS)
    ReDim Matrix(z,z)

    For i=0 To Ubound(PNTS)
    For j=0 To Ubound(line)
    dist = Rhino.Min(array(Rhino.Distance(PNTS(i), Rhino.CurveStartPoint(line(j))), Rhino.Distance(PNTS(i), Rhino.CurveEndPoint(line(j)))))
    If dist < e Then
    Rhino.AddText i, Rhino.CurveMidPoint(line(j)), 1.5
    Matrix(i, j) = 1
    End If
    If dist > e Then
    Matrix(i, j) = 0
    End If

    Next
    Next
    Rhino.Print Matrix(1, 0)

    End Sub

  • 6. alibek (Oct 05, 2016 20.39):

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version 4 ??????? 2016 ?. 23:40:16
    Call putpoints
    Sub PutPoints()
    Dim i,spoint,epoint,N,PNTS,pts
    ReDim PNTS(0)
    N = 0
    Const CurveConst = 4

    Dim line : line = Rhino.ObjectsByType(CurveConst)
    If IsNull(line) Then Rhino.Print("Nothing selected")
    If IsArray(line) Then
    For i=0 To Ubound(line)
    ReDim Preserve PNTS(N)
    PNTS(N) = Rhino.CurveStartPoint(line(i))
    N = N + 1
    ReDim Preserve PNTS(N)
    PNTS(N) = Rhino.CurveEndPoint(line(i))
    N = N + 1
    Next
    End If
    PNTS = Rhino.CullDuplicatePoints(PNTS)
    pts = Rhino.AddPoints(PNTS)
    For i=0 To ubound(PNTS)
    Rhino.addText i, PNTS(i), 1
    Next

    ReDim Lines(Ubound(line))
    Dim j,coord,dist,p
    For i=0 To ubound(line)
    Lines(i) = Array(Rhino.CurveStartPoint(line(i)), Rhino.CurveEndPoint(line(i)))
    Next
    Dim test_p
    Dim e:e = 1e-10
    Dim z
    z = Ubound(PNTS)
    ReDim Matrix(z,z)

    For i=0 To Ubound(PNTS)
    For j=0 To Ubound(line)
    dist = Rhino.Min(array(Rhino.Distance(PNTS(i), Rhino.CurveStartPoint(line(j))), Rhino.Distance(PNTS(i), Rhino.CurveEndPoint(line(j)))))
    If dist < e Then
    Rhino.AddText i, Rhino.CurveMidPoint(line(j)), 1.5
    Matrix(i, j) = 1
    End If
    If dist > e Then
    Matrix(i, j) = 0
    End If

    Next
    Next
    Rhino.Print Matrix(1, 0)

    End Sub

  • 5. alibek (Oct 05, 2016 20.34):

    if I write
    Rhino.Print Matrix(0, 0)
    it gives me the value of the point
    but if I write
    Rhino.Print Matrix(i,j)
    it gives me an error.

    So, I can see the values of Matrix Cells, but cannot see the whole Matrix itself...

  • 4. alibek (Oct 05, 2016 20.17):

    Thank's for your advice, it helped me a lot.
    But again, I am stuck with another problem...
    Can you please tell how I can visualise the Array I finally got.

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version 4 ??????? 2016 ?. 23:40:16
    Call putpoints
    Sub PutPoints()
    Dim i,spoint,epoint,N,PNTS,pts
    ReDim PNTS(0)
    N = 0
    Const CurveConst = 4

    Dim line : line = Rhino.ObjectsByType(CurveConst)
    If IsNull(line) Then Rhino.Print("Nothing selected")
    If IsArray(line) Then
    For i=0 To Ubound(line)
    ReDim Preserve PNTS(N)
    PNTS(N) = Rhino.CurveStartPoint(line(i))
    N = N + 1
    ReDim Preserve PNTS(N)
    PNTS(N) = Rhino.CurveEndPoint(line(i))
    N = N + 1
    Next
    End If
    PNTS = Rhino.CullDuplicatePoints(PNTS)
    pts = Rhino.AddPoints(PNTS)
    For i=0 To ubound(PNTS)
    Rhino.addText i, PNTS(i), 1
    Next

    ReDim Lines(Ubound(line))
    Dim j,coord,dist,p
    For i=0 To ubound(line)
    Lines(i) = Array(Rhino.CurveStartPoint(line(i)), Rhino.CurveEndPoint(line(i)))
    Next
    Dim test_p
    Dim e:e = 1e-10
    Dim z
    z = Ubound(PNTS)
    ReDim Matrix(z,z)
    For i=0 To Ubound(PNTS)
    Matrix(i, j) = 0
    Next
    For i=0 To Ubound(PNTS)
    For j=0 To Ubound(line)
    dist = Rhino.Min(array(Rhino.Distance(PNTS(i), Rhino.CurveStartPoint(line(j))), Rhino.Distance(PNTS(i), Rhino.CurveEndPoint(line(j)))))
    If dist < e Then
    Rhino.AddText i, Rhino.CurveMidPoint(line(j)), 1.5
    Matrix(i, j) = 1
    Else Matrix(i, j) = 0
    End If
    Next
    Next
    End Sub

  • 3. pulgarata (Oct 05, 2016 16.33):

    Look for VBscript information.
    A matrix is a 2D array. You can create it of this way:
    Redim YourMatrix (i,i)

    And you can fill it of same way of any value. For example:

    YourMatrix (0,3)= 0
    if true then YourMatrix (0,3)=1

  • 2. alibek (Oct 05, 2016 16.15):

    I want to create a zero matrix(i,i), where i=number of control points. And when the script finds the connecting line of two control points it will change the value of corresponding matrix cell to 1.
    Finally, the program should come up with such a matrix (which will allow the user to see which control points are connected)

    Please help me

    Create a Matrix
  • 1. alibek (Oct 05, 2016 16.14):

    I am stuck with matrix creation...
    My script shows which points are connected to each other, and prints a text along the connecting line. So that I can easily draw a matrix by hand. But, do not know how to make the programm draw that matrix. I simply do not know and did not find any Rhino commands to work with matrices.
    My question is:
    I want to create a zero matrix(i,i), where i=number of control points. And when the script finds the connecting line of two control points it will change the value of corresponding matrix cell to 1.

    Here is my script and picture of how it works.

    Option Explicit
    'Script written by <insert name>
    'Script copyrighted by <insert company name>
    'Script version 4 ??????? 2016 ?. 23:40:16
    Call putpoints
    Sub PutPoints()
            Dim i,spoint,epoint,N,PNTS,pts
            ReDim PNTS(0)
            N = 0
            Const CurveConst = 4
     
            Dim line : line = Rhino.ObjectsByType(CurveConst)
            If IsNull(line) Then Rhino.Print("Nothing selected")
            If IsArray(line) Then
                    For i=0 To Ubound(line)
                            ReDim Preserve PNTS(N)
                            PNTS(N) = Rhino.CurveStartPoint(line(i))
                            N = N + 1                      
                            ReDim Preserve PNTS(N)
                            PNTS(N) = Rhino.CurveEndPoint(line(i))
                            N = N + 1
                    Next
            End If
            PNTS = Rhino.CullDuplicatePoints(PNTS)
            pts = Rhino.AddPoints(PNTS)
            For i=0 To ubound(PNTS)
                    Rhino.addText i, PNTS(i), 1
            Next

            ReDim Lines(Ubound(line))
            Dim j,coord,dist,p
            For i=0 To ubound(line)
                    Lines(i) = Array(Rhino.CurveStartPoint(line(i)), Rhino.CurveEndPoint(line(i)))
            Next
            Dim test_p
            Dim e:e = 1e-10
            For i=0 To Ubound(PNTS)
                    For j=0 To Ubound(line)
                            dist = Rhino.Min(array(Rhino.Distance(PNTS(i), Rhino.CurveStartPoint(line(j))), Rhino.Distance(PNTS(i), Rhino.CurveEndPoint(line(j)))))
                            'Rhino.SelectObjects(array(pts(i), test_p))
                            If dist < e Then
                                    Rhino.AddText i, Rhino.CurveMidPoint(line(j)), 1.5
                            End If
                            'Rhino.UnselectObjects(array(pts(i), test_p))
                    Next
            Next
    End Sub

    Create a Matrix
Recommend

Why are these buttons gray?