Assasin писал(а):
Мда, у меня нечто невразумительное вышло Какая то катапульта... В моделировании нужно подходить последовательно.
Возникает сила --> Возникает ускорение --> меняется скорость --> меняется положение
Add(PaintBox,6464998,483,182)
{
Width=545
Height=520
Align=5
Color=16777215
}
Add(MMTimer,3013379,371,182)
{
Interval=10
link(onTimer,1688360:doDraw,[])
}
Add(InlineCode,1688360,434,182)
{
WorkPoints=#6:doDraw|
EventPoints=#6:onDraw|
DataPoints=#5:CDraw|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|21:uses kol,Share,Debug;|0:|4:type|17: TVector = record|14: x,y:double;|5: end;|1: |15: TBody = record|12: m:double;|14: x,y:double;|13: v:TVector;|5: end;|0:|28: THiAsmClass = class(TDebug)|10: private|14: p1:TBody;|14: t1:TBody;|9: public|28: CDraw,onDraw:THI_Event;|5: |24: constructor Create;|51: procedure doDraw(var _Data:TData; Index:word);|5: end;|0:|14:implementation|0:|37:procedure _debug(r:double); overload;|5:begin|24: _debug(double2str(r));|4:end;|0:|31:constructor THiAsmClass.Create;|5:begin|15: p1.m := 4E12;|14: p1.x := 200;|14: p1.y := 200;|14: p1.v.x := 0;|14: p1.v.y := 0;|2: |12: t1.m := 1;|14: t1.x := 200;|14: t1.y := 150;|14: t1.v.x := 1;|16: t1.v.y := 1.5;|4:end;|0:|29:procedure THiAsmClass.doDraw;|14:const t = 0.1;|16:var bmp:PBitmap;|14: a:TVector;|16: v,r2:double;|15: s,c:double;|5:begin|33: bmp := ReadBitmap(_Data,CDraw);|25: Bmp.BkColor := clWhite;|41: Bmp.Canvas.Brush.BrushStyle := bsSolid;|38: Bmp.Canvas.FillRect(Bmp.BoundsRect);|2: |66: r2 := (t1.x - p1.x)*(t1.x - p1.x) + (t1.y - p1.y)*(t1.y - p1.y);|14:// _debug(r);|28: v := 6.67E-11 * p1.m / r2;|33: c := -(t1.x - p1.x) / sqrt(r2);|33: s := -(t1.y - p1.y) / sqrt(r2);|20: a.x := c * v/t1.m;|20: a.y := s * v/t1.m;|29: t1.v.x := t1.v.x + a.x * t;|29: t1.v.y := t1.v.y + a.y * t;|28: t1.x := t1.x + t1.v.x * t;|28: t1.y := t1.y + t1.v.y * t;|2: |27: with bmp.Canvas^ do begin|28: pen.PenStyle := psSolid;|25: pen.Color := clBlack;|22: pen.PenWidth := 2;|32: brush.brushStyle := bsSolid;|27: brush.color := clBlack;|36: MoveTo(round(p1.x),round(p1.y));|40: LineTo(round(p1.x+2),round(p1.y+2));|36: MoveTo(round(t1.x),round(t1.y));|40: LineTo(round(t1.x+1),round(t1.y+1));|6: end;|22: _hi_onEvent(onDraw);|4:end;|0:|4:end.|
link(onDraw,6464998:doRefresh,[])
link(CDraw,6464998:Bitmap,[(440,170)(464,170)(464,226)(489,226)])
}
Вот решение для системы трех тел
Add(PaintBox,6464998,483,182)
{
Width=628
Height=525
Align=5
Color=16777215
}
Add(MMTimer,3013379,371,182)
{
Interval=10
link(onTimer,1688360:doDraw,[])
}
Add(InlineCode,1688360,434,182)
{
WorkPoints=#6:doDraw|
EventPoints=#6:onDraw|
DataPoints=#5:CDraw|
Code=#15:unit HiAsmUnit;|0:|9:interface|0:|21:uses kol,Share,Debug;|0:|4:type|17: TVector = record|14: x,y:double;|5: end;|1: |15: TBody = record|12: m:double;|14: x,y:double;|13: v:TVector;|5: end;|0:|28: THiAsmClass = class(TDebug)|10: private|14: p1:TBody;|14: p2:TBody;|14: t1:TBody;|9: public|28: CDraw,onDraw:THI_Event;|5: |24: constructor Create;|51: procedure doDraw(var _Data:TData; Index:word);|5: end;|0:|14:implementation|0:|37:procedure _debug(r:double); overload;|5:begin|24: _debug(double2str(r));|4:end;|0:|31:constructor THiAsmClass.Create;|5:begin|15: p1.m := 4E12;|14: p1.x := 190;|14: p1.y := 180;|14: p1.v.x := 0;|14: p1.v.y := 0;|2: |15: p2.m := 4E12;|14: p2.x := 200;|14: p2.y := 200;|14: p2.v.x := 0;|14: p2.v.y := 0;|2: |12: t1.m := 1;|14: t1.x := 200;|14: t1.y := 150;|14: t1.v.x := 4;|16: t1.v.y := 2.5;|4:end;|0:|29:procedure THiAsmClass.doDraw;|14:const t = 0.8;|16:var bmp:PBitmap;|14: a:TVector;|23: v1,v2,r1,r2:double;|15: s,c:double;|5:begin|33: bmp := ReadBitmap(_Data,CDraw);|27: //Bmp.BkColor := clWhite;|43: //Bmp.Canvas.Brush.BrushStyle := bsSolid;|40: //Bmp.Canvas.FillRect(Bmp.BoundsRect);|2: |66: r1 := (t1.x - p1.x)*(t1.x - p1.x) + (t1.y - p1.y)*(t1.y - p1.y);|66: r2 := (t1.x - p2.x)*(t1.x - p2.x) + (t1.y - p2.y)*(t1.y - p2.y);|14:// _debug(r);|29: v1 := 6.67E-11 * p1.m / r1;|29: v2 := 6.67E-11 * p2.m / r2;|80: a.x := (-(t1.x - p1.x) / sqrt(r1) * v1 - (t1.x - p2.x) / sqrt(r2) * v2) /t1.m;|80: a.y := (-(t1.y - p1.y) / sqrt(r1) * v1 - (t1.y - p2.y) / sqrt(r2) * v2) /t1.m;|29: t1.v.x := t1.v.x + a.x * t;|29: t1.v.y := t1.v.y + a.y * t;|28: t1.x := t1.x + t1.v.x * t;|28: t1.y := t1.y + t1.v.y * t;|2: |27: with bmp.Canvas^ do begin|28: pen.PenStyle := psSolid;|25: pen.Color := clBlack;|22: pen.PenWidth := 2;|32: brush.brushStyle := bsSolid;|27: brush.color := clBlack;|36: MoveTo(round(p1.x),round(p1.y));|40: LineTo(round(p1.x+2),round(p1.y+2));|36: MoveTo(round(p2.x),round(p2.y));|40: LineTo(round(p2.x+2),round(p2.y+2));|36: MoveTo(round(t1.x),round(t1.y));|40: LineTo(round(t1.x+1),round(t1.y+1));|6: end;|22: _hi_onEvent(onDraw);|4:end;|0:|4:end.|
link(onDraw,6464998:doRefresh,[])
link(CDraw,6464998:Bitmap,[(440,170)(464,170)(464,226)(489,226)])
}
orbita.png