Drawing Lines in 3D Space

Open In Colab

Install Urchin

Urchin is a Python package stored on PyPI, the following code needs to be run the first time you use Urchin in a Python environment.

Urchin’s full documentation can be found on our website.

[ ]:
#Installing urchin
!pip install oursin -U

Setup Urchin and open the renderer webpage

By default Urchin opens the 3D renderer in a webpage. Make sure pop-ups are enabled, or the page won’t open properly. You can also open the renderer site yourself by replacing [ID here] with the ID that is output by the call to .setup() at https://data.virtualbrainlab.org/Urchin/?ID=[ID here]

Note that Urchin communicates to the renderer webpage through an internet connection, we don’t currently support offline use (we hope to add support in the future).

[1]:
#Importing necessary libraries:
import oursin as urchin
urchin.setup(localhost=True)
(URN) connected to server
Login sent with ID: ba7313bc, copy this ID into the renderer to connect.

Line tutorial below

To create a group of lines, call the urchin.lines.create(n) function, passing the number of lines as a parameter. The create function returns a list of lines objects, which can then be passed to the singular functions to set the position, color, size (etc) each line individually.

[2]:
lines = urchin.lines.create(3) #Creating 3 lines stored in list lines

Urchin has a zero based index, meaning that the first line is line[0], and the last of the three is line[2].

[ ]:
lines[0].delete() #deletes the first line

Urchin can take in color input in different formats, including hex codes, RGB floats, and RGB ints. Urchin uses hex colors represented as strings by default, but you can also pass colors as lists or tuples. The followig examples are all equivalent: lines[i].set_color((0,255,0)) lines[i].set_color([0,255,0]) lines[i].set_color((0,1.0,0)) lines[i].set_color("00FF00")

After changing the colors, move the camera around some to see the shift in color.

[ ]:
#Setting colors to make lines visible
lines[1].set_color("#000000") #Setting second line to black
lines[2].set_color("#FF0000") #Setting third line to red

Positions are passed in as 3 coordinates consisting of xyz values. For readability, it is easier to create the positions array before passing it into to the lines[i].set_position() function.

[ ]:
tempPositions = [[0,0,0],[1000,2000,3000],[4000,4000,4000]]  #creating array of coordinates to set position of line

lines[1].set_position(tempPositions) #Setting second line to positions array above
[ ]:
tempPositions2 = [[16,47,82], [2847,304,782], [10004,859,3641]] #creating array of coordinates to set position of line

lines[2].set_position(tempPositions2) #Setting third line to positions array above