- Mein Physiklehrer behauptete, innerhalb einer Kugel würden sich die Coulombkräfte komplett aufheben. Wenn man sich die Formel ansieht kommt raus
wobei D der unwichtige Formelrest ist und r der Radius Probeladung-Kugel_ladung, wobei alle Kugelladungen regelmäßig verteilt auf der kugel sitzen. Wird r jetzt unendlich klein, also der Abstand Ladung der Kugel zu Probeladung, dann wird die Kraft unendlich groß und das kann von andren Kräften nicht ausgeglichen werden. sprich -> auf Kugel wirkt eine Coulombkraft!
Code: Alles auswählen
F = D * ( 1/r² )
Ich habe heute während des Unterrichts schnell und unauffällig eine Simulationssoftware geschrieben, die sagts wie folgt:
Tastaturbelegung:
- drücke F6 zum Kugel-hinzufügen [oder rechts]
und F1 zum Löschen der Ladungen,
F4 zum einschalten der Vektoraddition, die alle KraftVektoren einfach aneinanderkettet.
siehe angezeigten Programmtext.
DOWNLOAD Exe + Code
Code: Alles auswählen
; Coulombkraft Simulator
; (c) Aigner, Max
; Erstellt am 12.01.2010 um 11:30
; in Purebasic 4.10
#Window_0 = 0
#max_pfeillength = 30
Enumeration ; mausart
#mouse_art_none
#mouse_art_tipped
#mouse_art_pressed
#mouse_art_Released
EndEnumeration
Structure vector
x.f
y.f
x2.f ; zielx
y2.f ; ziely
EndStructure
Structure ladung
x.f
y.f
farbe.i
vec.vector ; ihr vektor, der angezeigt wird..
EndStructure
Structure probeladung
x.f
y.f
EndStructure
Global screenwidth.w = 770
Global screenheight.w = 480
Global mousex.f
Global mousey.f
Global mousebutton1.w
Global mousebutton2.w
Global mousedeltax.w
Global mousedeltay.w
Global circle_width.f = 440
Global circle_height.f= 440
Global circle_x.f = screenwidth / 2 - circle_width / 2
Global circle_y.f = screenheight/2 - circle_width / 2
Global button_add_x = 130
Global button_add_y = 40
Global button_add_width = 90
Global button_add_height = 30
Global button_del_x = 200
Global button_del_y = 80
Global button_del_width = 90
Global button_del_height = 30
Global is_anziehend = 1
Global status_display_kraftplan = 0
Global status_display_krafte = 1
Global status_move_probeladung
Global NewList ladung.ladung()
Global probeladung.probeladung
Macro Formel()
(( is_anziehend * 1.6 * 1.6)/( 4* #PI * 8.85) )/ Pow(math_get_dist ( probeladung\x , probeladung\y , ladung()\x , ladung()\y )/10 ,2) * 1000000
EndMacro
; deklarationen:
;{ Declarations
Declare ladung_add( x.f = -1 , y.f = -1)
Declare ladung_verschieben(x.f,y.f) ; berechnen aller neuen Vectoren
Declare Displaystuff()
Declare.f math_get_dist( x.f , y.f, x2.f , y2.f) ; gibt betrag zurück
Declare math_vec_copy ( *vec.vector , *target.vector)
Declare math_vec_normalize( *vec.vector) ; vector auf länge 1 normalisieren.
Declare mouse_in_box( x.f,y.f,width.f,height.f)
Declare examine ( menumodus = 0 )
Declare ende ()
Declare MouseStatus ( Button )
Declare initstuff()
;}
Procedure initstuff()
InitSprite()
InitKeyboard()
UseJPEGImageEncoder()
ExamineDesktops ( )
If OpenWindow(#Window_0, 130, 0, 836, 522, "physik", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
OpenWindowedScreen ( WindowID(#Window_0) , 30 , 70 , screenwidth , screenheight , 0 , WindowWidth(#Window_0) - 770 , WindowHeight(#Window_0) - 640)
EndIf
EndProcedure
Procedure MouseStatus ( Button )
If Button = 1
ProcedureReturn mousebutton1
ElseIf Button = 2
ProcedureReturn mousebutton2
ElseIf Button=3
ProcedureReturn mousebutton3
EndIf
EndProcedure
Procedure ende ()
End
EndProcedure
Procedure examine ( menumodus = 0 )
Protected markieren_endx , markieren_endy
ExamineKeyboard ( )
FlipBuffers ( )
ClearScreen (23 )
ladung_verschieben ( mousex , mousey )
If IsWindow ( #Window_0 )
If WaitWindowEvent( 10 ) = #PB_Event_CloseWindow
ende ()
EndIf
EndIf
;{ mousestuff..
If IsWindow ( #Window_0 )
windowx= WindowX( #Window_0) + 30
windowy= WindowY ( #Window_0 ) + 70 + 20
EndIf
smousex = mousex
smousey = mousey
mousex = DesktopMouseX() - windowx
mousey = DesktopMouseY() - windowy
mousedeltax = smousex - mousex
mousedeltay = smousey - mousey
If getasynckeystate_( 1 )
If mousebutton1 = 0
mousebutton1 = 1
ElseIf mousebutton1 = 1
mousebutton1 = 2
EndIf
Else
If mousebutton1 > 0 And mousebutton1 < 3
mousebutton1 = 3
Else
mousebutton1 = 0
EndIf
EndIf
If getasynckeystate_( 2 )
If mousebutton2 = 0
mousebutton2 = 1
ElseIf mousebutton2 = 1
mousebutton2 = 2
EndIf
Else
If mousebutton2 > 0 And mousebutton2 < 3
mousebutton2 = 3
Else
mousebutton2 = 0
EndIf
EndIf
;}
If MouseStatus(1) > 0
ladung_verschieben( mousex , mousey )
EndIf
If MouseStatus( 2 ) = #mouse_art_tipped
ladung_add( mousex , mousey )
EndIf
If KeyboardReleased( #PB_Key_F2 )
is_anziehend = 1
EndIf
If KeyboardReleased( #PB_Key_F3 )
is_anziehend = -1
EndIf
If KeyboardReleased(1)
ende()
EndIf
If KeyboardReleased (#PB_Key_F4 )
If status_display_kraftplan = 0
status_display_kraftplan = 1
status_display_krafte = 0
Else
status_display_kraftplan = 0
status_display_krafte = 1
EndIf
EndIf
If KeyboardReleased ( #PB_Key_F5 )
If status_display_krafte = 0
status_display_krafte = 1
Else
status_display_krafte = 0
EndIf
EndIf
If KeyboardPushed(#PB_Key_F6 )
;Delay(1)
ladung_add( )
EndIf
If KeyboardReleased ( #PB_Key_F7)
anzahl = Val( InputRequester("Physik Projekt" ,"Geben Sie die gewünschte anzahl Ladungen ein" , "10"))
ClearList ( ladung())
For x = 1 To anzahl
ladung_add()
Next
EndIf
If KeyboardReleased(#PB_Key_F1)
ClearList( ladung())
EndIf
EndProcedure
Procedure mouse_in_box( x.f,y.f,width.f,height.f)
If mousex > x And mousey > y
If mousex + width < x And mousey + height < y
ProcedureReturn 1
EndIf
EndIf
EndProcedure
Procedure math_vec_normalize( *vec.vector) ; vector auf länge 1 normalisieren.
If *vec < = 0 : ProcedureReturn : EndIf
lange.f = *vec\x2 - *vec\x ; x - abschnitt
breite.f = *vec\y2 - *vec\y ; y - abschnitt
gesamt.f = Sqr( lange *lange + breite* breite ) ; diagonale berechnen
lange / gesamt
breite / gesamt
*vec\x2 = *vec\x + lange
*vec\y2 = *vec\y + breite
EndProcedure
Procedure math_vec_copy ( *vec.vector , *target.vector)
*target\x = *vec\x
*target\x2 = *vec\x2
*target\y = *vec\ y
*target\y2 = *vec\y2
EndProcedure
Procedure.f math_get_dist( x.f , y.f, x2.f , y2.f) ; gibt betrag zurück
x2 = Abs(x2) - Abs(x )
y2 = Abs(y2) - Abs(y )
ProcedureReturn Sqr( x2 *x2 + y2* y2 )
EndProcedure
Procedure Displaystuff()
Protected vec.vector
Protected veclengh.f
; anzeigen von kreis und ladungen.
; sowie buttons
If StartDrawing( ScreenOutput())
DrawingMode( #PB_2DDrawing_Outlined )
Circle ( circle_x+ circle_width/2 , circle_y + circle_height/2 , circle_width / 2 , RGB(255,23,23))
DrawText ( 10 , 2 , "clear ladungen: F1 Q*q > 0 : F2 Q*q < 0 : F3 Display Vektorplan F4 Display Vektoren F5 ")
DrawText ( 10 , 17 , "Add ladung: Rechtsklick F6: Quick add Ladungen F7: Manuelle Ladungszahl-Eingabe" )
DrawText ( 10 , 32 , "(c) Aigner Max, Gemusoft." )
DrawText ( 10 , 47 , "erstellt am 12.01.11 um 11:12 Uhr")
DrawingMode( #PB_2DDrawing_Default )
Circle ( probeladung\x , probeladung\y , 10 , RGB( 23,255,23))
; vectoren ausrechnen und anzeigen als striche.
ForEach ladung()
If status_display_krafte = 1
ladung()\vec\x2 = ladung()\x
ladung()\vec\y2 = ladung()\y
ladung()\vec\x = probeladung\x
ladung()\vec\y = probeladung\y
math_vec_copy ( ladung()\vec , vec)
veclengh = Formel()
math_vec_normalize( vec ) ; dann hab ich die richtung
LineXY( probeladung\x , probeladung\y , (vec\x2 - vec\x ) * veclengh + probeladung\x, (vec\y2 - vec\y )* veclengh + probeladung\y , ladung()\farbe)
EndIf
Circle( ladung()\x +3, ladung()\y+3 , 8 , ladung()\farbe)
Next
; anzeigen des kräfteplans:
If status_display_kraftplan
x = screenwidth/ 2
y = screenheight / 2
ForEach ladung()
ladung()\vec\x2 = ladung()\x
ladung()\vec\y2 = ladung()\y
ladung()\vec\x = probeladung\x
ladung()\vec\y = probeladung\y
veclengh = Formel()
math_vec_copy( ladung()\vec , vec )
math_vec_normalize( vec )
breite = (vec\x2 - vec\x ) * veclengh
hohe = (vec\y2 - vec\y ) * veclengh
LineXY ( x , y , x + breite , y + hohe , ladung()\farbe )
x + breite
y + hohe
Next
LineXY ( screenwidth /2 , screenheight / 2 , x , y , RGB(255,0,0))
x = (x + screenwidth/2 ) / 2
y = (y + screenheight/2 ) / 2
DrawText ( x , y , "F RES (rote linie)" , RGB( 255,0,0))
EndIf
StopDrawing( )
EndIf
EndProcedure
Procedure ladung_verschieben(x.f,y.f) ; berechnen aller neuen Vectoren
; bei maus-linksklick wird einfach dahin verschoben
probeladung\x = x
probeladung\y = y
EndProcedure
Procedure ladung_add_alt( x.f = -1 , y.f = -1)
Protected vec.vector, *ladung.ladung
If x = -1 Or y = -1 ; randommäßig hinzufügen
x = Random( screenwidth )
y = Random( screenheight )
EndIf
vec\x = screenwidth / 2
vec\y = screenheight /2
vec\x2 = x
vec\y2 = y
math_vec_normalize ( vec )
length = circle_width / 2
vec\x2 = (vec\x2 -vec\x) * length
vec\y2 = (vec\y2 -vec\y) * length
AddElement( ladung())
ladung()\x = vec\x2 + screenwidth / 2
ladung()\y = vec\y2 + screenheight /2
ladung()\farbe = RGB( Random(245) + 10 , Random(245) + 10 , Random(245) + 10 )
*ladung = ladung()
AddElement ( ladung() )
ladung()\x = screenwidth /2 -vec\x2
ladung()\y = screenheight /2 - vec\y2
ladung()\farbe = *ladung\farbe
EndProcedure
Procedure ladung_add(x.f = -1 , y.f = -1 )
Protected vec.vector, *ladung.ladung , deltafi.f , listsize, Fi.f , z
AddElement( ladung())
ladung()\farbe = RGB( Random(245) + 10 , Random(245) + 10 , Random(245) + 10 )
listsize = ListSize( ladung())
deltafi = 2*#PI / listsize
ForEach ladung()
ladung()\x = Cos( Fi )* circle_width / 2 + screenwidth / 2
ladung()\y = Sin( Fi )* circle_height / 2 + screenheight / 2
Fi + deltafi
Next
EndProcedure
initstuff()
Repeat
examine()
Displaystuff()
ForEver
; IDE Options = PureBasic 4.41 (Windows - x86)
; CursorPosition = 56
; FirstLine = 32