Skip to content

Instantly share code, notes, and snippets.

@numberlesstim
numberlesstim / Heavy Humpy.craft
Last active August 12, 2024 20:29
KSP craftfile for Heavy Humpy
ship = Heavy Humpy
version = 1.12.5
description =
type = VAB
size = 18.887188,66.6988144,18.8873024
steamPublishedFileId = 0
persistentId = 1154365171
rot = 0,0,0,0
missionFlag = Squad/Flags/flag_nbl_tim
vesselType = Debris
@numberlesstim
numberlesstim / EllipseUtils.ks
Last active August 12, 2024 13:32
Library for Elliptical Orbit Math
//gist cbd2551d7ef78d370d2ef2949b2233f3
function getAltitudeAtAnomaly {
parameter _ta.
parameter _Ap is apoapsis.
parameter _Pe is periapsis.
parameter _r is body:radius.
local _a is (_Ap + _Pe)/2 + _r.
local _le is _a - _Pe - _r.
// ABANDONED
// Do not run this. Paste via telnet (or TPSKP runscript)
// FTLToolbox.ks
// gist 02e8a05fb7fb02dddb28bb5e59dfb460
// v0.2.5
//TODO:
//implement printing
//gist 77d66bc51a59854a30f7f2cbe2ad0e05
function getAltitudeAtAnomaly {
parameter _ta.
parameter _Ap is apoapsis.
parameter _Pe is periapsis.
parameter _r is body:radius.
local _a is (_Ap + _Pe)/2 + _r.
local _le is _a - _Pe - _r.
//gist 49ee151859597d8f62c8127a5e408b6c
function sort {
parameter inputItems.
parameter comparator is {
//true --> a further down the list (sorting small to big for numbers)
parameter a, b.
return a > b.
}.
//gist a78133867a86ab42b8c302c628084473
set cc to kuniverse:craftlist.
set cleanlist to list().
for i in range(cc:length) if unchar(cc[i]:tostring()[15]) <> 34 cleanlist:add(cc[i]).
unset cc.
function printPrintalist {
parameter printalist.
//gist 19f6bdb4dd3063de4acb0b70e6b37d63
function matchVelAtNode {
parameter nodeX is nextnode.
parameter tarvel is "none".
set tx to nodeX:time.
set nodeX:prograde to 0.
set nodeX:radialout to 0.
//gist 5e22d396270c7856977f5d3ff394ec11
set pointer to lex().
set pointer:target to ship:rootpart.
set pointer:speed to 150.
set pointer:color to white.
set pointer:vd to vecdraw(v(0,0,0), v(0,0,0), white, "", 1, true, 0.08, true, false).
set pointer:size to 3.
set pointer:bounce to 0.2.
set pointer:offset to 1.
//gist 035e4a80c4d83198dd20129f6d630195
function getDriftVector {
parameter acceleration. //magnitute of your acceleration (through engines) as scalar (m/s^2)
parameter targetVector. //direction you want to accelerate in as (normalized) vector
parameter gravity. //gravity-acceleration as vector
if targetVector:mag = 0 return targetVector.
if acceleration = 0 return v(0,0,0).
//gist b6459854660e43e0138b8bb1d2e8c629
approach on.
decelflag off.
if not (defined fliptime) set fliptime to 35. //how long does it take the ship to flip 180 degrees?
if not (defined sleepdist) set sleepdist to 50. //how far away from the tarpos should it simply keep stopped?
if not (defined sleepspd) set sleepspd to .001. //how slow is slow enough to qualify as 'stopped'?
if not (defined estSize) set estSize to 50. //estimated size of target if not loaded
if not (defined sl) set sl to -1. //how fast should it approach the target at most? -1 -> dv limited