Ver código fonte

Redid function prototypes, added some basic functions, wrote
documentation strings.

I've added some new function prototypes, added a couple of constants,
and wrote a whole bunch of documentation strings.

Samuel W. Flint 9 anos atrás
pai
commit
a7bc76515c
1 arquivos alterados com 111 adições e 6 exclusões
  1. 111 6
      cl-ballistics.lisp

+ 111 - 6
cl-ballistics.lisp

@@ -2,8 +2,6 @@
 
 (in-package #:cl-ballistics)
 
-;;; "cl-ballistics" goes here. Hacks and glory await!
-
 ;;; Constant definitions
 (defconstant +gravity+ -32.194)
 
@@ -15,10 +13,26 @@
 
 (defconstant +standard-altitude+ 0)
 
-(defconstant +standard-temperature+ 32)
+(defconstant +standard-temperature+ 59)
 
 (defconstant +standard-humidity+ 1)
 
+;;; Alist of Drag Functions
+(defconstant +drag-functions+
+  '((:g1 . "Ingalls, flatbase")
+    (:g2 . "Aberdeen \"J\" Projectile")
+    (:g3 . "")
+    (:g4 . "")
+    (:g5 . "Short, 7.5° boat-tail")
+    (:g6 . "Flatbase, 6 Calibers long")
+    (:g7 . "Long 7.5° boat-tail")
+    (:g8 . "Flatbase, 10 Calibers long")))
+
+;;; Solution class
+
+(defclass ballistic-solution ()
+  ())
+
 ;;; Atmospheric Functions
 
 (defun calc-fp (pressure)
@@ -65,29 +79,41 @@
 
 ;;; G-function retardation
 
+;; (defun retard (drag-function drag-coefficient velocity)
+;;   (declare (integer drag-function)
+;;            (real drag-coefficient velocity))
+;;   (let (())
+;;     ))
+
 ;;; Angular conversion functions
 
 (defun degrees-to-moa (degrees)
+  "Converts degrees to Minutes of Angle."
   (declare (real degrees))
   (* degrees 60))
 
 (defun degrees-to-radians (degrees)
+  "Converts Degrees to Radians"
   (declare (real degrees))
   (* degrees +to-radians+))
 
 (defun moa-to-degrees (moa)
+  "Converts Minutes of Angle to Degrees"
   (declare (real moa))
   (/ moa 60))
 
 (defun moa-to-radians (moa)
+  "Converts Minutes of Angle to Radians"
   (declare (real moa))
   (degrees-to-radians (moa-to-degrees moa)))
 
 (defun radians-to-degrees (radians)
+  "Converts Radians to Degrees"
   (declare (real radians))
   (* radians +to-degrees+))
 
 (defun radians-to-moa (radians)
+  "Converts Radians to Minutes of Angle"
   (declare (real radians))
   (degrees-to-moa (radians-to-degrees radians)))
 
@@ -100,17 +126,21 @@
 
 ;;; Windage functions
 
-(defun windage (wind-speed vi xx tv)
-  (declare (real wind-speed vi xx tv))
+(defun windage (wind-speed initial-velocity range time)
+  "Calculates the windage correction, in inches, to achive zero on
+   target at given range."
+  (declare (real wind-speed initial-velocity range time))
   (let ((wind-speed-inches-per-second (* wind-speed 17.60)))
-    (* wind-speed-inches-per-second (/ (- tv xx) vi))))
+    (* wind-speed-inches-per-second (/ (- time range) initial-velocity))))
 
 (defun head-wind (wind-speed wind-angle)
+  "Calculates the Headwind component in miles per hour"
   (declare (real wind-speed wind-angle))
   (* (cos (degrees-to-radians wind-angle))
      wind-speed))
 
 (defun cross-wind (wind-speed wind-angle)
+  "Calculates the crosswind components in miles per hour"
   (* (sin (degrees-to-radians wind-angle))
      wind-speed))
 
@@ -120,8 +150,83 @@
 
 ;;; Bore angle functions
 
+(defun zero-angle (drag-function ballistic-coefficient initial-velocity sight-height zero-range y-intercept)
+  "Calculates the angle of the bore, relative to the sighting system in degrees."
+  (declare (keyword drag-function)
+           (real ballistic-coefficient
+                 initial-velocity
+                 sight-height
+                 zero-range
+                 y-intercept))
+  (let ((nit 0)
+        (dt (/ 1 initial-velocity))
+        (y (/ sight-height 12))
+        (x 0)
+        (da 0)
+        (v 0) (vx 0) (vy 0)
+        (vx1 0) (vy1 0)
+        (dv 0) (dvx 0) (dvy 0)
+        (gx 0) (gy 0)
+        (angle 0)
+        (quit 0))
+    (declare (real nit
+                   dt
+                   y
+                   x
+                   da
+                   v vx vy
+                   vx1 vy1
+                   dv dvx dvy
+                   gx gy
+                   angle)
+             (integer quit))
+    (loop for angle = (+ angle da)
+       if (= quit 1)
+       return (radians-to-degrees angle)
+       else
+         )))
 
 ;;; Solving
 
+(defun solve-all (drag-function drag-coefficient initial-velocity sight-height shooting-angle zero-angle wind-speed wind-angle)
+  "Generates a ballistic solutions table."
+  (declare (keyword drag-function)
+           (real drag-coefficient
+                 initial-velocity
+                 sight-height
+                 shooting-angle
+                 zero-angle
+                 wind-speed
+                 wind-angle)))
 
 ;;; Retrieving Data
+
+(defun get-range (solution yardage)
+  "Retrieve range in yards.")
+
+(defun get-path (solution yardage)
+  "Retrieves projectile pathin inches, relative to the line of sight at yardage.")
+
+(defun get-moa (solution yardage)
+  "Retrieves the estimated elevation correction for zero at specified range.
+Very useful for \"click charts\" and similar.")
+
+(defun get-time (solution yardage)
+  "Retrieves the time of flight to this range.")
+
+(defun get-windage (solution yardage)
+  "Retrives the windage correction, in inches, required to achieve
+zero at this range.")
+
+(defun get-windage-moa (solution yardage)
+  "Retrieves windage correction in MOA to achieve zero at this range.")
+
+(defun get-velocity (solution yardage)
+  "Retrieves velocity of projectile at specified yardage.")
+
+(defun get-velocity-bore (solution yardage)
+  "Retrives projectile's velocity in the direction of the bore.")
+
+(defun get-velocity-perpendicular (solution yardage)
+  "Retireves the velocity of the projectile perpendicular to the
+direction of the bore.")