"""Example: 'point in frame'

The simple example above shows how to use a frame as a coordinate system:
Starting from a point `P` in the local (user-defined, relative) coordinate
system of frame `F`, i.e. its position is relative to the origin and orientation
of `F`, we want to get the position `P_` of `P` in the global (world, absolute)
coordinate system.
"""
from compas.geometry import Point
from compas.geometry import Vector
from compas.geometry import Frame
from compas.geometry import allclose

point = Point(146.00, 150.00, 161.50)
xaxis = Vector(0.9767, 0.0010, -0.214)
yaxis = Vector(0.1002, 0.8818, 0.4609)

F = Frame(point, xaxis, yaxis)  # coordinate system F
P = Point(35., 35., 35.)  # point in F (local coordinates)

P_ = F.to_world_coords(P)  # point in global (world) coordinates
print("The point's world coordinates: {}".format(P_))

P2 = F.to_local_coords(P_)
print("The point's local coordinates: {}".format(P2))  # should equal P
print(allclose(P2, P))
"""Example: 'frame in frame'
"""
from compas.geometry import Point
from compas.geometry import Vector
from compas.geometry import Frame

point = Point(146.00, 150.00, 161.50)
xaxis = Vector(0.9767, 0.0010, -0.214)
yaxis = Vector(0.1002, 0.8818, 0.4609)
F0 = Frame(point, xaxis, yaxis)  # coordinate system F0

point = Point(35., 35., 35.)
xaxis = Vector(0.604, 0.430, 0.671)
yaxis = Vector(-0.631, 0.772, 0.074)
f_lcf = Frame(point, xaxis, yaxis)  # frame f_lcf in F0 (local coordinates)

# frame in global (world) coordinate system
f_wcf = F0.to_world_coords(f_lcf)
print(f_wcf)

f_lcf2 = F0.to_local_coords(f_wcf)  # world coords back to local coords
print(f_lcf2)  # should equal f_lcf
print(f_lcf == f_lcf2)
"""Change-basis transformation vs transformation between two frames.
"""
from compas.geometry import Point
from compas.geometry import Frame
from compas.geometry import Transformation

F1 = Frame([2, 2, 2], [0.12, 0.58, 0.81], [-0.80, 0.53, -0.26])
F2 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])

# transformation between 2 frames F1, F2
Tf = Transformation.from_frame_to_frame(F1, F2)
# change-basis transformation between two frames F1 and F2.
Tc = Transformation.change_basis(F1, F2)

# they are different
print(Tf)
print(Tc)

# This is how to use Tf: transform geometry into another coordinate frame
pt = Point(2, 2, 2)
pt.transform(Tf)
print(pt, "==", F2.point)

# This is how to use Tc: represent geometry in another coordinate frame
pt = Point(0, 0, 0)  # local point in F1
pt.transform(Tc)
print(pt, "==", F2.to_local_coords(F1.point))