Hanging a straight line is of course right in theory, but it is difficult to operate. Put a slender stick (such as chopsticks) under the cake, rotate the cake, let the chopsticks pass through the corresponding position of point P on the cake, then find the balance point and cut along the direction of the chopsticks. How about that?
If you write a paper, the above principle can be explained by the following mechanics (or geometry) knowledge: if the static moment of a section to an axis is zero, then the axis must pass through the center of mass of the section.