import Quaternion
import vec3

# create a quaternion
q1 = Quaternion.Quaternion(3,5,7,8)

# create another quaternion
# this time using angle and axis
q2 = Quaternion.Quaternion(0.6,vec3.vec3(0,0,1))

# create another quaternion
q3 = q2+q1

# create a list to store our Quaternion objects
quats = []
quats.append(q1)
quats.append(q2)
quats.append(q3)

# write these quaternions to a file
# 1 quaternion per line
with open('quats.txt','a') as file:
    for quat in quats:
        file.write(str(quat.w)+','+str(quat.x)+','+str(quat.y)+','+str(quat.z))
        file.write('\n')

# now,read quaternions from the file
with open('quats.txt') as file:
    line1 = file.readline().strip()
    line2 = file.readline().strip()

# create more quaternions
q4 = Quaternion.Quaternion(line1)
q5 = Quaternion.Quaternion(line2)

# add to quaternion list
quats.append(q4)
quats.append(q5)

# check some operations and create a few more quaternions
q4 = q4+q5
q5 = q5/2
q6 = q1+q2
q7 = q1-q4
q8 = -q7

# add to quaternion list
quats.append(q6)
quats.append(q7)
quats.append(q8)

# add these quaternions to the file
with open('quats.txt','a') as file:
    for quat in quats:
        file.write(str(quat.w)+','+str(quat.x)+','+str(quat.y)+','+str(quat.z))
        file.write('\n')
