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