Skip to content

Instantly share code, notes, and snippets.

View lamont-granquist's full-sized avatar

Lamont Granquist lamont-granquist

View GitHub Profile
@lamont-granquist
lamont-granquist / FastFloatCurve.cs
Created May 16, 2026 17:58 — forked from gotmachine/FastFloatCurve.cs
C# cubic hermite spline implementation similar to an Unity AnimationCurve, but faster
/// <summary>
/// A collection of keys mapping times to values, interpolated between keys by a cubic Hermite spline. <para/>
/// The implementation produce identical results as a UnityEngine.AnimationCurve, but calling Evaluate() is at least twice faster. <para/>
/// However, it doesn't support keys in/out weights, and behavior is always identical to WrapMode.ClampForever.
/// </summary>
public class FastFloatCurve : IEnumerable<FastFloatCurve.Key>, IConfigNode
{
/// <summary>
/// Define how a key tangent will be adjusted.
/// </summary>
# Açıkmeşe & Ploen (2007), J. Guidance, Control, and Dynamics 30(5):1353–1366
# "Convex Programming Approach to Powered Descent Guidance for Mars Landing"
#
# A Julia/JuMP implementation of Problem 4 (the discretised second-order cone
# program). Algorithm 1 of the paper line-searches the integer number of
# time-steps N to find the optimal time-of-flight; the cost is unimodal in N,
# so we scan upward from N_min and stop once the objective has been
# increasing for a few consecutive steps.
#
# Run with:
[LOG 11:42:25.734] ******* Log Initiated for Kerbal Space Program - 1.12.3.3173 (OSXPlayer) en-us *******
Kerbal Space Program - 1.12.3.3173 (OSXPlayer) en-us
OS: Mac OS X 26.3.0
CPU: Apple M4 (10)
RAM: 32768
GPU: Apple M4 (25559MB)
SM: 46 (OpenGL 4.1 Metal - 90.5)
RT Formats: ARGB32, Depth, ARGBHalf, Shadowmap, RGB565, ARGB4444, ARGB1555, Default, ARGB2101010, DefaultHDR, ARGB64, ARGBFloat, RGFloat, RGHalf, RFloat, RHalf, R8, BGRA32, RGB111110Float, RG32, RG16, BGRA10101010_XR, BGR101010_XR, R16
Mono path[0] = '/Users/lamont/ksp/vanilla_1.12.3/KSP.app/Contents/Resources/Data/Managed'
Mono config path = '/Users/lamont/ksp/vanilla_1.12.3/KSP.app/Contents/MonoBleedingEdge/etc'
Initialize engine version: 2019.4.18f1 (3310a4d4f880)
[Subsystems] Discovering subsystems at path /Users/lamont/ksp/vanilla_1.12.3/KSP.app/Contents/Resources/Data/UnitySubsystems
GfxDevice: creating device client; threaded=1
Renderer: Apple M4
Vendor: Apple
Version: 4.1 Metal - 90.5
GLES: 0
GL_ARB_blend_func_extended GL_ARB_draw_buffers_blend GL_ARB_draw_indirect GL_ARB_ES2_compatibility GL_ARB_explicit_attrib_location GL_ARB_gpu_shader_fp64 GL_ARB_gpu_shader5 GL_ARB_instanced_arrays GL_ARB_internalformat_query GL_ARB_occlusion_query2 GL_ARB_sample_shading GL_ARB_sampler_objects GL_ARB_separate_shader_objects GL_ARB_shader_bit_encoding GL_ARB_shader_subroutine GL_ARB_shading_language_include GL_ARB_tessellation_shader GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_cube_map_array GL_ARB_texture_gather GL_ARB_texture_quer
[LOG 12:53:11.443] ******* Log Initiated for Kerbal Space Program - 1.12.3.3173 (OSXPlayer) en-us *******
Kerbal Space Program - 1.12.3.3173 (OSXPlayer) en-us
OS: Mac OS X 26.3.0
CPU: Apple M4 (10)
RAM: 32768
GPU: Apple M4 (25559MB)
SM: 46 (OpenGL 4.1 Metal - 90.5)
RT Formats: ARGB32, Depth, ARGBHalf, Shadowmap, RGB565, ARGB4444, ARGB1555, Default, ARGB2101010, DefaultHDR, ARGB64, ARGBFloat, RGFloat, RGHalf, RFloat, RHalf, R8, BGRA32, RGB111110Float, RG32, RG16, BGRA10101010_XR, BGR101010_XR, R16
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "auglag.h"
int auglag_verbose = 0;
#define MIN(a,b) ((a) < (b) ? (a) : (b))
using Optim
using Roots
using LinearAlgebra
using LineSearches
using Pkg
evaluations = 0
local_path = joinpath(@__DIR__, "..", "AstroUtils.jl")
function dX_dt = EOM1(t, X)
global indexes
r = X(indexes.r);
v = X(indexes.v);
r2 = dot(r,r);
rm = sqrt(r2);
r3 = r2 * rm;
clear all; close all; clc;
format longG;
k = 1
M = 1
w = sqrt(k/M)
r0 = 0
v0 = 1
FlightCtrlState ctrlState = base.part.vessel.ctrlState;
inputVector = new Vector3(ignorePitch ? 0f : ctrlState.pitch, ignoreRoll ? 0f : ctrlState.roll, ignoreYaw ? 0f : ctrlState.yaw);
float num = actuatorSpeed * TimeWarp.fixedDeltaTime / ctrlSurfaceRange;
if (!useExponentialSpeed)
{
rotatingControlInput.x = Mathf.MoveTowards(rotatingControlInput.x, inputVector.x, num);
rotatingControlInput.y = Mathf.MoveTowards(rotatingControlInput.y, inputVector.y, num);
rotatingControlInput.z = Mathf.MoveTowards(rotatingControlInput.z, inputVector.z, num);
}
else