이미 다른 방향으로 발사 중이므로 두 구성 요소로 정의 된 속도 벡터가 있다고 가정합니다. (x, y)
. JavaFX에서 이러한 벡터는 Point2D
으로 나타낼 수 있습니다.
public void fire() {
// the point at which you are shooting
Point2D target = ...
// the point from where you are shooting
Point2D source = ...
// the projectile speed per frame
double speed = ...
// velocity vector to be used to move
// the projectile at constant speed per frame
Point2D velocity = target.subtract(source).normalize().multiply(speed);
}
UPDATE : (각도에서 포함 벡터 생성)
경우에는 대상 지점을 모르는, 당신이 얻을 수있는 speed
당신이 다음을 수행 할 수 있습니다, 발사체에서 여행 싶어을 감안할 때 촬영에 사용하는 각도의 벡터 :
public void fire() {
double angleDegrees = ...
double angleRadians = Math.toRadians(angleDegrees);
// the point from where you are shooting
Point2D source = ...
// the projectile speed per frame
double speed = ...
Point2D shootingVector = new Point2D(Math.cos(angleRadians), Math.sin(angleRadians));
// velocity vector to be used to move
// the projectile at constant speed per frame
Point2D velocity = shootingVector.normalize().multiply(speed);
}
안녕하세요. AlmasB, 저는 Vector Math로 완전 초보자입니다. 하위의 x, y 좌표가 있습니다. 고정 된 각도 (30, 45, 90 등)로 어뢰를 발사하고 싶습니다. 이 화재 방법으로 속도를 입력하여 어뢰의 경로를 어떻게 생성합니까()? 당신의 도움을 주셔서 감사합니다! – user1104028
업데이트 된 답변을 참조하십시오. 그래픽에서 우리는 양수 Y가 내려 가고 수학에서 양수 Y가 올라 가기 때문에 Y 축을 조정해야 할 수도 있습니다. – AlmasB
안녕 AlmasB, VectorBrowser에서 NewBie가되는 것처럼, shootingVector에는 투영 물에 대한 각도와 속도를 지정하면 투영법에서 따라야하는 X 및 Y 증분 이동이 포함됩니다. (나는 투영법을 따라야 할 x, y 점의 배열을 생성하려고합니다) 감사합니다! – user1104028