`Demonstrates combining heeling moments
`Finds max VCG for a series of drafts.

proj hmmt2

read fv
report

wind 90
variable radius=500, speed=16
variable n=0

lim area from abs 0 to ra0 > 10

macro hmrep
if "%1"<>"" then hmmt report
/

macro mx `%1 - draft
heel 0
trim {tr}
draft %1
if "%2"<>"" then vcg %2 else vcg %1
solve weight, lcg
hmmt wind
.hmrep %2
variable hm1={HMMT}
hmmt turn {radius}, {speed}
.hmrep %2
set hm1={hm1} plus {HMMT}
hmmt {hm1} /c1 `Heeling moment is now the sum at zero heel times cosine heel
.hmrep %2
vcg 0
solve maxvcg
if "%2"="" then exit mx %1 {FVCG} `repeat with the preliminary max VCG to refine turn hmmt
page
ra /lim
set n={n} plus 1
variable dr{n}=%1, vc{n}={VCG}
/

variable tr=0 `trim angle
.mx (6,0.5) 5

macro summ
\{ dr%1:3} { vc%1:3}\
me {dr%1}, {vc%1}
/

page
\ Draft Max VCG\
me plotstart "Max VCG vs draft at trim={tr:2} degrees"
me plotlabel "Draft", "Max VCG"
.summ ({n},1) 1
me plotend

print preview
report off
end