[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 8 KB, 389x332, pudlak.png [View same] [iqdb] [saucenao] [google]
5631065 No.5631065 [Reply] [Original]

Help me /sci/, you're my only hope.

I'm making a robot that can shoot another robot. Unfortunately I can only get the enemy robot's x,y when I look at it. So if I get it's position twice (assuming it is basically traveling in a straight line)... What angle should I shoot at depending on the velocity of my bullet to hit the moving robot?

>> No.5631075

Is this a vector problem?

>> No.5631084

>>5631065
From delta (x,y)/t you have velocity. Call your robots position the origin. Therefore the target's position as a function of time is (x0,y0)+v*t. Your robot shoots a projectile at time t=0, from the origin, at speed v_2 and angle theta. So the projectile has position function v_2*(cos(theta),sin(theta))*t. You want there to exist some t such that the target and the bullet are at the same point. You have two equations in two unknowns, so you can solve for t and theta. All you actually need is theta.

>> No.5631096

Have you tried taking intro physics?

>> No.5631118
File: 62 KB, 755x657, 1359293146672.png [View same] [iqdb] [saucenao] [google]
5631118

>>5631084
thanks anon.

So it seems like there are multiple ways of solving for theta.

I have

theta = arcsin( enemy_y_velocity / bullet_velocity)

and

theta = arccos( enemy_x_velocity / bullet_velocity)

Are these the same things? Or did I do something wrong?

>> No.5631133

>>5631118
You did something wrong. Both X and Y velocity will need to be accounted for to achieve an exact firing solution.

Close approximations can be achieved, however, with just proper motion and range, presuming bullet velocity is significantly faster than target velocity.

>> No.5631142

>>5631133
So what does theta equal?

>> No.5631152

>>5631142
Target velocity = (x2-x1, y2-y1)
Target initial position = (x2, y2)
SO
Target position = (x2 + (x2-x1)*t, y2 + (y2-y1)*t) where t is time

AND
Bullet velocity = (v*cos(theta), v*sin(theta))
SO
Bullet position = (v*t*cos(theta), v*t*sin(theta)) as a function of T

Find the conditions where Target position (t, theta) = Bullet position (t, theta)

>> No.5631708

>>5631118
You don't actually have to solve for theta. Solve for, e.g. sin(theta), using the identity sin^2(x)+cos^2(x)=1 to write cos(theta) = sqrt(1-sin^2(theta)). Then you don't have to bother with inverse sin functions. You still have to eliminate the ambiguity of sign in the square root, though--the solution for cos(theta) might be a negative number.

>> No.5631747

i need a couple questions answered first

is the bullet going straight or is it following a projectile trajectory? trig will be needed for projectile, otherwise, vector "language" is sufficient to describe the "angle" of the shot

"depending on the velocity of the bullet." how fast relative to the robot? because having 2 points cannot give you an accurate shot since it cannot tell you whether the robot is accelerating/decelerating/constant velocity. having 3 points would, 4 points could even describe the changing of the acceleration (2nd derivative)

its not a hard question to solve, its just a matter of getting the details right. its like equating two equations together, where one side describes the motion of the robot, and the other side describes the motion of the bullet, then solving for the unknown in this case being the angle of the shot.

if your robot is at the origin. the position of the target robot can be described as folllow (in the simplest case):

x1, y1 at t0
x2, y2 at t1
(x(tn),y(tn)) = (tn(x2-x1), tn(y2-y1)) assuming the target is traveling at the constant speed

since any resulting position can be determined after t1, the bullet can be fired at any time, the earliest being t1 and hit the target.

target position at tn = bullet position at tn when fired at an earlier known time

given the bullet speed, the angle can be determined if you are at origin and knowing the target position (= bullet position at the same time)