how to import a csv file to vpython to 3d simulate

76 views
Skip to first unread message

Saul Bernal

unread,
Oct 10, 2015, 5:21:16 PM10/10/15
to VPython-users
Hello. I have a csv file the have a matrix of coodinates (x,y,z) that i want to 3d simulate.

class buttom:

   

   

    def load_files(self):

        

        dlg = wx.FileDialog(None,message="Choose File",wildcard= '*.txt;*.csv', defaultFile="",style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST|wx.FD_CHANGE_DIR)

    

        if dlg.ShowModal() == wx.ID_CANCEL:

                print ('buh cancelaste')

    

        else:

            filename=dlg.GetFilename()

            f = open(filename)

            #f = open('test1.csv', 'rb') # opens the csv file

            try:

                reader = csv.reader(f,  delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')  

            

          

                for column in reader:   # iterates the rows of the file in orders

            

                    print (type(column))

                    print (column)

            

                    

        

            finally:

                f.close()      # closing


          

    files = wx.Button(pan, label='Load Coordinates', pos=(x1+280,570), size = (150,40))

    files.Bind(wx.EVT_BUTTON, load_files)


how can i do the my csv file, vpython can 3d simulate my coordinates values using a wxpython evtbutton.

example:

Asis = sphere(pos= (MYCOORDINATESVALUES), make_trail=True, radius = 0.02, color=color.blue, retain= 200)

 


Bruce Sherwood

unread,
Oct 10, 2015, 9:27:21 PM10/10/15
to vpytho...@googlegroups.com
I"m not sure what your question is, but I'll make a guess. When you read from a file you can obtain a sequence of numbers which in your case probably represent x1, y1, z1, x2, y2, z2, etc.

A sphere object is an object which has a pos attribute that is one location in space, (x,y,z) or, more precisely, vector(x,y,z). You can't give a list of points as the pos of a sphere.

I suggest you look at the documentation for the points object, which does accept a list of (x,y,z) locations.

Reply all
Reply to author
Forward
0 new messages