これは実際のプログラミングの質問というよりも数学の質問ですが、私はC++
andを使用しCOCOS2D-X
ているので、ここに投稿することにしました。
CCBezierTo
スプライトが実行するベジエの動きを作成するために使用していますmySprite
。この構造体は、 、、およびの 3 つの点 ( )CCBezierConfig
を受け入れます。2 つの は、ベジエがカーブするポイントです。CCPoint
controlPoint_1
controlPoint_2
endPoint
controlPoint
ここで質問です。曲線を作成するために必要な sはcontrolPoint
不明であり、少し計算することによってのみ取得できます。これらは既知の変数です。下の図を参照してください。
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: 線は右上から左下へ
前もって感謝します。