# Trajectory.py
# Author: Juliette Zerick (jnzerick@math.ucdavis.edu)
# EAD 221 + PHY 250 (Spring 2009)
# Purpose: This encapsulates a Trajectory, or a list of points in a
#	finite-dimensional space. Note that the plotting method must be
#	supplied.

from UtilsNConstants import *

class Trajectory:
	# start with a list of points--NOT deep copied
	# and a function handle to a plotting function
	def __init__(self,fh_plot,P):
		self.points = P
		self.fh_plot = fh_plot

	# add a point to the Trajectory
	def feed_point(self,P):
		self.points.append(P)

	# plot the Trajectory using the given plotting function
	def plot_traj(self):
		L = []

		# first, repack the points into a set of vectors
		if len(self.points) == 0:
			return

		for i in xrange(len(self.points[0])):
			V = []

			for j in xrange(len(self.points)):
				V.append(self.points[j][i])

			L.append(V)

		# then plot
		self.fh_plot(L)

	# copy method--provides a DEEP copy of the points list
	def copy(self):
		P = []
		for i in xrange(len(self.points)):
			P.append(copylist(self.points[i]))

		return Trajectory(self.fh_plot,P)
