This paper focuses on the three dimensional flight path planning for an unmanned aerial vehicle (UAV) on a low altitude terrain following\terrain avoidance mission. The UAV trajectory planning problem is to compute an optimal or near-optimal trajectory for a UAV to do its mission objectives in a surviving penetration through the hostile enemy environment, considering the shape of the earth and the kinematics constraints of the UAV. Using the three dimensional terrain information, three dimensional flight path from a starting point to an end point, minimising a cost function and regarding the kinematics constraints of the UAV is calculated. The geographic information of the earth shape and enemy locations is generated using digital terrain model (DTM) and geographic information system (GIS), and is displayed in a 3D environment. Using 3D-maps containing the geographic data accompanied by DTM, and GIS, the problem is modelled by deriving the motion equations of the UAV. Two heuristic algorithms are proposed for this problem: genetic and particle swarm algorithms. Genetic and particle swarm algorithms are general purposes algorithms, because they can solve a wide range of problems, so they have to be adjusted to solve the trajectory planning problem. To test and compare the paths obtained from these algorithms, a software program is built using GIS tools and the programming languages C# and MATLAB.