A trajectory control device for moving a trajectory tracking member along a trajectory on a workpiece that is placed in an arbitrary position, the trajectory control device comprising: a contact sensor configured to contact side surfaces of the workpiece; an actuator configured to move the trajectory tracking member and the contact sensor; and a trajectory controller configured to calculate XY coordinates of the trajectory on the workpiece placed in the arbitrary position, by transforming XY coordinates of the trajectory on the workpiece in a reference position, based on positional information about the side surfaces of the workpiece in the reference position and positional information about the side surfaces of the workpiece placed in the arbitrary position, wherein the positional information about the side surfaces of the workpiece placed in the arbitrary position is obtained by the contact sensor, characterized in that the trajectory controller detects XY coordinates of two contact points on one side surface of the workpiece by driving the actuator to advance the contact sensor in two movement directions that are parallel to an X axis, and detects XY coordinates of two contact points on another side surface of the workpiece by driving the actuator to advance the contact sensor in two movement directions that are parallel to a Y axis, and the trajectory controller obtains an equation of a first straight line that passes through the two contact points on the one side surface of the workpiece and an equation of a second straight line that passes through the two contact points on the another side surface of the workpiece, further obtains XY coordinates of an intersection of the first straight line and the second straight line, then calculates an amount of movement of an X coordinate and an amount of movement of a Y coordinate of a reference point of the workpiece, and also calculates a gradient angle of the another side surface of the workpiece with respect to the reference position of the workpiece. a contact sensor configured to contact side surfaces of the workpiece; an actuator configured to move the trajectory tracking member and the contact sensor; and a trajectory controller configured to calculate XY coordinates of the trajectory on the workpiece placed in the arbitrary position, by transforming XY coordinates of the trajectory on the workpiece in a reference position, based on positional information about the side surfaces of the workpiece in the reference position and positional information about the side surfaces of the workpiece placed in the arbitrary position, wherein the positional information about the side surfaces of the workpiece placed in the arbitrary position is obtained by the contact sensor, characterized in that the trajectory controller detects XY coordinates of two contact points on one side surface of the workpiece by driving the actuator to advance the contact sensor in two movement directions that are parallel to an X axis, and detects XY coordinates of two contact points on another side surface of the workpiece by driving the actuator to advance the contact sensor in two movement directions that are parallel to a Y axis, and the trajectory controller obtains an equation of a first straight line that passes through the two contact points on the one side surface of the workpiece and an equation of a second straight line that passes through the two contact points on the another side surface of the workpiece, further obtains XY coordinates of an intersection of the first straight line and the second straight line, then calculates an amount of movement of an X coordinate and an amount of movement of a Y coordinate of a reference point of the workpiece, and also calculates a gradient angle of the another side surface of the workpiece with respect to the reference position of the workpiece.