Profile image

Funky Trees Magic: Computerized Artillery

67.1k SnoWFLakE0s  5.0 years ago

Hello all, I'm back with more Funky Trees magic... This time around, here's some juicy math for a computerized artillery system. Enjoy.

The objective of this system is to generate an input statement for a rotator such that given an range defined by the operator, the system automatically calculates the required elevation in degrees for the gun such that it will reach that defined range. Here's a diagram of the situation:

As with the diagram, we'll call the initial velocity of the projectile Vi and the angle that it is launched at Ø. We assume no air resistance. This means that to go range you need exactly Ø amount of elevation. As such, we can derive the following equation from the diagram:

  • range = vi * cosØ * t

where range is the horizontal distance we want the projectile to travel, and t the time it takes for the projectile to reach the target area. We now need to solve for t, which we do not know- luckily, since the projectile travels in a parabola, we know that the time spent for the projectile to reach the maximum height is the same coming down. As such, the total time spent by the projectile in the air will be defined as:

  • t = ((vi * sinØ) / 9.81)*2

Now if we substitute this expression in for t in the original equation, we get:

  • range = vi * cosØ * vi * sinØ * 1/9.81 * 2
  • Which simplifies to:
  • range = vi^2 * 2cosØsinØ / 9.81

Ah, very nice! We see a Pythagorean identity here- the double angle formula. According to this Pythagorean identity, we know that: 2sinØcosØ = sin(2Ø), therefore if we substitute for that in the equation above, we get:

  • range = v^2 * sin(2Ø) / 9.81

Now we can do algebra to solve for Ø:

  • (range * 9.81)/(v^2) = sin(2Ø)
  • asin((range * 9.81)/(v^2)) = 2Ø, so
  • Ø = asin((range * 9.81)/(v^2))/2

Now that we have the mathematical equation for the angle Ø in the initial launch of a projectile, we now need to convert it into a format that SimplePlanes recognizes. To do this, we need to think of how our system will work. My system works by the operator (you, the user) inputting the range by changing the Trim input. It will be actuated by a piston, so we now need to set a maximum value for the system. Let's try 5000m (5km) as our max range. Then this means the for an Trim input value of 1, the range should be set as 5000m... Therefore, if we determine the function for range, R(Trim), using Trim, we get:

  • Range = 5000 * Trim

Which makes sense as trim should be the respective proportion of the range 5000m. Now if we replace range as 5000 * Trim, we get that our angle equation is:

  • Ø = asin((5000 * Trim * 9.81)/(pow(vi, 2)))/2

I also converted the square of the projectile velocity into the pow() function. Now, if we consider that our cannon will be placed on a rotator with an allowed angle of 90º, then we know that the angle Ø should be a proportion of 90º. If we do this, we finally get that the input statement for the cannon elevation rotator is:

(asin((5000 * Trim * 9.81)/(pow(vi, 2)))/2)/a

Where vi is the projectile initial velocity and a the allowed angle of the rotator. For my system, the statement is set to (asin((5000 * Trim * 9.81)/(pow(300, 2)))/2)/90, as my rotator is set to 90º and the projectile velocity 300m/s.

Well, I've gone ahead and done exactly that. Here's a view of the interface:

The clock on the righthand corner is a shell splash timer, displaying the expected airtime of the projectile. This is just regulated by the expression for t we found earlier converted into SP syntax ((((vi * sin(asin((5000 * Trim * 9.81)/(pow(vi, 2)))/2))/9.81) * 2) * (12/90))).

I'll release this computerized artillery system by maybe tomorrow. If you liked my work, please leave an upvote or two. Stay tuned for the actual build!

  • Log in to leave a comment
  • Profile image
    67.1k SnoWFLakE0s

    Expect this to be out by today!

    Pinned 5.0 years ago
  • Profile image
    37.7k V

    Forgot about air resistance

    5.0 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @BaconAircraft
    .
    Hahaha, this wouldn't have worked if drag was modelled for the ingame cannons...

    5.0 years ago
  • Profile image

    Great work.
    A sSuMe AiR rEsIstA nC e and OThE r NoN-c OnsEva Tive foRcEs aRe Ne g Lig i ble gives me PTSD from my shitty dynamics prof

    5.0 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @GeneralOliverVonBismarck
    .
    Sure, it's out now so go give it a look. Feel free to use.

    5.0 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @BuiltBionixInd10
    .
    Not yet. I'm not so good with mechs, but I will look into them given the chance.

    5.0 years ago
  • Profile image

    @SnoWFLakE0s have you tried making a mech with this one with the use of Funky trees

    5.0 years ago
  • Profile image
    770 NaCltm

    Making a new SPG, this will be useful.

    5.0 years ago
  • Profile image

    Once again, we have been outdone by a simple snowflake...

    +6 5.0 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @XxMegamonsterxX
    .
    It's not a setting or anything.

    5.0 years ago
  • Profile image
    4,623 TheMaus

    The setting for the funky trees.

    5.0 years ago
  • Profile image
    4,623 TheMaus

    I couldn’t find it on my SP on iOS

    5.0 years ago
  • Profile image
    162k spefyjerbf

    Ah. Makes sense. Well done!

    5.0 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @spefyjerbf
    .
    Yep, it's a distance approximator essentially. You just adjust the viewing angle to the target, the computer calculates the distance traveled by the target and divides it by a reference timeframe to obtain the target velocity.

    5.0 years ago
  • Profile image
    162k spefyjerbf

    I probably wouldn’t be able to follow the math, but I assume that some sort of trig is responsible?

    5.0 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @spefyjerbf
    .
    Ah, I've already created an object velocity approximator device to do exactly that. The math is solid, if you want to view it I can show you my work related to it.

    5.0 years ago
  • Profile image

    My head is burning, but I'm fine

    +1 5.0 years ago
  • Profile image
    162k spefyjerbf

    Leading a target would be difficult as there are no inputs that are directly related to its velocity. Perhaps some sort of estimation might have to happen.

    5.0 years ago
  • Profile image
    32.3k CRJ900Pilot

    Sweet! Way too much math for me, but I can’t wait to test it out

    5.0 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @spefyjerbf
    .
    Thanks. Originally, meant to make a full-on fire control system with automatic lead compensation based on flight time and target velocity, but I can only solve it via vector mathematics right now and I'm figuring out a way to convert that into the appropriate syntax for the input system. This was possible to do with normal kinematics so I did this first.

    +1 5.0 years ago
  • Profile image

    Nice, I wish y’all the best of luck. I hope to see this in the game!

    5.0 years ago
  • Profile image
    162k spefyjerbf

    Very nice. Good use of projectile motion functions.

    5.0 years ago