This study develops an optimal driving strategy for solar car on a track with nonzero gradients and sharp corners. This strategy consists of finding the racing line and the speed profile that minimizes the lap time with a given amount of energy. The problem is formulated in proper form for a commercial nonlinear optimization software program. The track is modeled into segments identified by their spatial coordinates on its own surface. The speed-distance behavior of the vehicle is linearized at each segment. The constraints set by the brushless DC motor, battery, and circuit are formulated accordingly. This is the motor type widely used in electric cars. The solver produces both the positions of the car on the track and entry speeds into the segments, which minimizes the lap time for the given amount of the solar power and battery reserve. The positions of the car describe the best racing line. Formulation of the constraints allows extracting the motor current profile from the speed profile, which comprises the set of control actions. These profiles help the human driver identify where and how much to accelerate along the track for the desired performance of the car. The algorithm presented here can also serve as a tool to assess the performance of an electric car at different road conditions, thus helping to choose the best settings of the motor and the car.