How to use the points object tikzpy.pto

Examples of how to use the point object tikzpy.pto.

Example 1 - Add and copy points

Test code:

 1#!/usr/bin/python
 2
 3### Load tikzpy library
 4import tikzpy as py_tikZ
 5
 6### Load main object
 7tikZ = py_tikZ.pytikz()
 8
 9### Add point at x=0, y=0, z=0
10p1 = tikZ.pto.pto(0.1,0.2,0.3, layer=0, alias='pto1')
11
12p2 = tikZ.pto.pto(1.1,1.2,1.3, layer=0, alias='pto2')
13print( p2)
14
15### How to call a point?
16p3 = tikZ.pto.pto(1.1,1.2,1.3, layer=0, alias='pto3')
17print(  p3.id == tikZ.pto.alias('pto3').id) #Is True
18print(  p3.id == tikZ.pto[p3.id].id )#Is True
19print(  p3.id == (p3*2).id) #Is False
20
21### How to make ne point?
22p4 = tikZ.pto.pto(1.2,1.3,1.4, layer=0, alias='pto4')
23print( p4)
24p5 = p4 # Assignment by reference (same pointer)
25print( p5)
26p5 = p4.copy() # Copy a new point with no alias
27print( p5)
28p5 = p4.copy('pto5') # Copy a new point with alias
29print( p5)
30
31### Operations return an axuiliary point
32p2 = p2 + 1 #p2 becomes an auxiliary point
33print( p2, p2.id == tikZ.pto.alias('pto2').id)
34
35### To modify the point coord use .xyz
36p2 = tikZ.pto.alias('pto2')
37p2.xyz = p2 + 1
38print( p2, p2.id == tikZ.pto.alias('pto2').id)
39p2.xyz = p2 + 1
40print( p2, p2.id == tikZ.pto.alias('pto2').id)

This would output:

Point key:#1 x=1.1000 y=1.2000 z=1.3000 layer=0 alias=pto2 NumPoints:2

True

True

False

Point key:#3 x=1.2000 y=1.3000 z=1.4000 layer=0 alias=pto4 NumPoints:4

Point key:#3 x=1.2000 y=1.3000 z=1.4000 layer=0 alias=pto4 NumPoints:4

Point key:#4 x=1.2000 y=1.3000 z=1.4000 layer=0 alias= NumPoints:5

Point key:#5 x=1.2000 y=1.3000 z=1.4000 layer=0 alias=pto5 NumPoints:6

Point key:None x=2.1000 y=2.2000 z=2.3000 layer=0 alias= NumPoints:6 False

Point key:#1 x=2.1000 y=2.2000 z=2.3000 layer=0 alias=pto2 NumPoints:6 True

Point key:#1 x=3.1000 y=3.2000 z=3.3000 layer=0 alias=pto2 NumPoints:6 True

Example 2 - Operate with points

Test code:

 1#!/usr/bin/python
 2
 3### Load tikzpy library
 4import tikzpy as py_tikZ
 5
 6### Load main object
 7tikZ = py_tikZ.pytikz()
 8# or
 9tikZ = py_tikZ.load()
10
11### Add point at x=0, y=0, z=0
12p1 = tikZ.pto.pto(0.1,0.2,0.3, layer=0, alias='pto1')
13
14### Add point at x=1, y=1, z=1
15p2 = tikZ.pto.pto(1,1,1, layer=0, alias='pto2')
16
17########### Operations
18
19### Vector between point 1 and 2 as auxiliary point
20vec = p2 - p1
21
22print( "01-", p1)
23print( "02-", p2)
24print( "03-", vec)
25
26### Conversion of auxiliary into point
27vec.save()
28vec.alias = "vec"
29print( "04-", vec)
30
31### Scaling a point into an auxiliary point
32p3 = p2 * 2.
33print( "05-", p3)
34
35### Scaling a point and modify the values
36tikZ.pto[p2.id] = p2 * 2.
37#or
38p2.xyz = p2 * 2.
39print( "06-", p2)
40
41### Array multiplication
42print( "07-", p1 * p2)
43
44### Adding a real number
45print( "08-", p1 + 3.)
46
47### Proof
48print( "09-", p1 == p2)
49print( "10-", p1 != p2)
50print( "11-", p1 != p1)
51print( "12-", p1 == p1)
52
53### Searching by alias
54pp1 = tikZ.pto.alias("vec")
55pp2 = tikZ.pto.alias("pto1")
56print( "13-", pp1)
57print( "14-", pp2)

This would output:

01- Point key:#0 x=0.1000 y=0.2000 z=0.3000 layer=0 alias=pto1 NumPoints:2

02- Point key:#1 x=1.0000 y=1.0000 z=1.0000 layer=0 alias=pto2 NumPoints:2

03- Point key:None x=0.9000 y=0.8000 z=0.7000 layer=0 alias= NumPoints:2

04- Point key:#2 x=0.9000 y=0.8000 z=0.7000 layer=0 alias=vec NumPoints:3

05- Point key:None x=2.0000 y=2.0000 z=2.0000 layer=0 alias= NumPoints:3

06- Point key:#1 x=4.0000 y=4.0000 z=4.0000 layer=0 alias=pto2 NumPoints:3

07- Point key:None x=0.4000 y=0.8000 z=1.2000 layer=0 alias= NumPoints:3

08- Point key:None x=3.1000 y=3.2000 z=3.3000 layer=0 alias= NumPoints:3

09- False

10- True

11- False

12- True

13- Point key:#2 x=0.9000 y=0.8000 z=0.7000 layer=0 alias=vec NumPoints:3

14- Point key:#0 x=0.1000 y=0.2000 z=0.3000 layer=0 alias=pto1 NumPoints:3

Example 3 - Visualize, translate and rotate points

Points can be visualized, translated and rotated

See the following example:

../../_images/test_pto_03_view_points.tikz.png

Drawing created with the following tikzpy code:

 1#!/usr/bin/python
 2
 3### Load tikzpy library
 4import tikzpy as py_tikZ
 5import random, os, sys
 6
 7### Load main object
 8tikZ = py_tikZ.load()
 9
10### Create a cloud of points
11max_number = 100
12radius = 10
13ptos = []
14
15for i in range(0,max_number):
16    ### Random points
17    x, y, z = random.uniform(-radius, radius), \
18              random.uniform(-radius, radius), \
19              random.uniform(-radius, radius)
20              
21    ### Create a point
22    p = tikZ.pto.pto(x, y, z, layer=0, alias='pto%i' %i)
23    
24    ### List of points
25    ptos.append(p.id)
26
27ptosB = tikZ.pto.copy(ptos, alias_prefix = "B-")
28ptosC = tikZ.pto.copy(ptos, alias_prefix = "C-")
29
30tikZ.pto.translate(ptosB, x=(2*radius)*1.1)
31tikZ.pto.translate(ptosC, x=(4*radius)*1.1)
32
33#tikZ.pto.rotate(ptosC, pto_rotation = None, Ax = 0., Ay = 0., Az = 0.)
34    
35### Show points
36tikZ.pto.draw_points(ptos, color = "black")
37tikZ.pto.draw_points(ptosB, color = "red")
38tikZ.pto.draw_points(ptosC, color = "blue")
39
40### Make drawing
41path = os.path.dirname(os.path.abspath(__file__))
42name = os.path.basename(os.path.abspath(__file__))
43name = os.path.splitext(name)[0]
44tikZ.save_pdf(path, name)
45
46
47
48
49

Example 4 - Read csv file with points

Points can be visualized, translated and rotated

See the following example:

../../_images/test_pto_04_read_points.tikz.png

Drawing created with the following tikzpy code:

 1#!/usr/bin/python
 2
 3### Load tikzpy library
 4import tikzpy as py_tikZ
 5import random, os, sys
 6
 7### Load main object
 8tikZ = py_tikZ.load()
 9tikZ.scale=1.
10
11### Create a cloud of points
12def _read_csv(tikZ, file_name):
13    path = os.path.dirname(os.path.abspath(__file__))
14    path = os.path.join(path, file_name)
15    #read csv file
16    ptos = tikZ.pto.read_list_csv(path, delimiter = None)
17    #scale points coordinates
18    sc = 1 /100.
19    tikZ.pto.scale(ptos, Sx = sc, Sy = sc, Sz = 1., pto_origin= None)
20    #return list of points
21    return ptos
22
23ptos_1 = _read_csv(tikZ, r"profile_10.csv")    
24ptos_2 = _read_csv(tikZ, r"profile_11.csv")    
25    
26### Show points
27tikZ.pto.draw_points(ptos_1, color = "black")
28tikZ.pto.draw_points(ptos_2, color = "black")
29
30### Make drawing
31path = os.path.dirname(os.path.abspath(__file__))
32name = os.path.basename(os.path.abspath(__file__))
33name = os.path.splitext(name)[0]
34tikZ.save_pdf(path, name)
35
36
37
38
39