In robotic-assisted heart surgery, the method of canceling the relative motion between the surgical site on the heart and the surgical instruments was introduced in this paper. A whisker sensor was designed for three dimensional position measurement in beating heart surgery. Analytical models were developed according to the classical mechanics of materials, and theoretical formulas were derived for displacement measurement. Feasibility and effectiveness of the method were verified by simulation experiments. We can obtain measurements by loading displacement to the whisker sensor, and draw conclusions by comparing the measurements.