In this paper, we address the current issues of the traditional bidirectional Cartesian (BC) scanning trajectory when NP, the frequency ratio and integer coefficient, is two times an odd number. Low scanning density and discontinuous waveforms are introduced by the conventional formula when the phase angle is not properly chosen. We proposed a new and better formula for ensuring continuity and specifying the phase angle for optimal scanning density. To maximize the density pattern for all Np values, set φ=0 for NP/2=even and φ=p//2 for NP/2=odd cases. The new formula adjusts the mathematical expressions for the waveforms of the current in the driving coils in both x and y directions. The major correction ensures a smooth transition of the trajectory by preserving the continuity between the two halves of the waveform, which are switched at half of the repeat period. Quantification of pattern density and quality of magnetic particle imaging-reconstructed images demonstrated that the new formula is simple to use and provides consistent performance and accuracy when compared to the best cases in the old formula. This improved bidirectional Cartesian trajectory formula provide a more effective and useful solution for a variety of high-precision scanning applications, including microscopy, imaging and automated inspection.