这更像是一个数学问题,而不是一个实际的编程问题,但由于我使用的是C++and COCOS2D-X,所以我选择在这里发布它。
我正在使用CCBezierTo创建精灵mySprite运行的贝塞尔运动。该CCBezierConfig结构接受三个点 ( CCPoints):controlPoint_1、controlPoint_2和endPoint。两个controlPoints 是贝塞尔曲线将弯曲的点。
现在问题来了。我需要创建曲线的controlPoints 是未知的,只能通过做一些数学来获得。这些是已知的变量。请参考下图。
A = The start point of the curve
B = The end point of the curve
Line AB = The line created by connecting A and B together
L = The distance between A and B/The length of Line AB
D = The distance between the line and the unknown points
我正在尝试寻找 X 和 Y。我已经实现了一点,但只有当线条是水平或垂直时:
// From left to right:
ccBezierConfig bezierConfig;
bezierConfig.controlPoint_1 = CCPointMake( A.x + ( L * 0.25f ), A.y + aCertainHeight );
bezierConfig.controlPoint_2 = CCPointMake( A.x + ( L * 0.75f ), A.y - aCertainHeight );
bezierConfig.endPoint = B;
/** CCPointMake( x, y ) is a macro that creates a CCPoint object, which is a point on a plane.
It accepts two float values determining the X and Y position of the point.**/
// From top to bottom:
ccBezierConfig bezierConfig;
bezierConfig.controlPoint_1 = CCPointMake( A.x + aCertainWidth, A.y - ( L * 0.25f ) );
bezierConfig.controlPoint_2 = CCPointMake( A.x - aCertainWidth, A.y - ( L * 0.25f ) );
bezierConfig.endPoint = B;
如果线是对角线,我怎样才能得到 X 和 Y?
案例1:线从左到右开始

案例2:线从左上到右下

案例3:线从右上到左下开始

提前致谢。