נבנה על ידיBuilt by Ariel Yohimovich

חזרה למפגשBack
PythonPython

Physics Lab: מעבדת סימולציותPhysics Lab

מפגש 44: חלקיקים, בד Verlet, משחק החיים ולהקות Boids.Session 44: Particles, Verlet cloth, the Game of Life and Boids flocks.

מה נעשה היוםToday's plan

  • וקטוריםVectors
  • כוחותForces
  • זריקהThrow
  • קפיץSpring
  • מסלולOrbit
  • מעבדהLab
נושאTopic 1

וקטוריםVectors

וקטוריםVectors

  • Vector2: חיבור, כפל, אורךVector2: add, scale, length
  • normalize() = כיוון באורך 1normalize() = a direction of length 1
  • שורה אחת במקום x ו-y בנפרדOne line instead of x and y separately

אנלוגיהAnalogy

וקטור הוא כמו חץ על מפה: יש לו כיוון ויש לו אורך, ואפשר לשרשר חצים: "3 צפונה ואז 4 מזרחה" הוא חץ אחד באורך 5.A vector is like an arrow on a map: it has a direction and a length, and arrows chain: "3 north then 4 east" is one arrow of length 5.

טעות נפוצהCommon mistake

vectors.py
from pygame.math import Vector2
print(Vector2(0, 0).normalize())
מה Python עונהWhat Python says
ValueError: Can't normalize Vector of length zero
ValueError: Can't normalize Vector of length zero: אין כיוון לחץ באורך 0. בודקים if v.length() > 0: לפני.ValueError: Can't normalize Vector of length zero: an arrow of length 0 has no direction. Check if v.length() > 0: first.
נושאTopic 2

כוחותForces

כוחות ותאוצהForces and acceleration

  • כוח → תאוצה: a = F / mForce → acceleration: a = F / m
  • אוילר: v += a*dt, p += v*dtEuler: v += a*dt, p += v*dt
  • כמה כוחות = מחברים וקטוריםSeveral forces = add the vectors

אנלוגיהAnalogy

סימולציה היא כמו לצעוד במגפיים בחושך: בכל צעד מסתכלים לאן הכוחות מושכים, מתקנים כיוון קצת, וצועדים שוב.A simulation is like walking in boots in the dark: every step you feel where the forces pull, adjust a little, and step again.
נושאTopic 3

זריקהThrow

זריקה ומסלולThrowing and trajectory

  • מהירות התחלתית לפי זוויתInitial velocity from an angle
  • סימולציה מול נוסחהSimulation vs formula
  • dt קטן = מדויק יותרSmaller dt = more accurate

אנלוגיהAnalogy

dt הוא כמו מספר התמונות בסרטון האטה: מעט תמונות = קפיצות ושגיאות, הרבה תמונות = תנועה חלקה ומדויקת.dt is like the frame count in a slow-motion video: few frames = jumps and errors, many frames = smooth, accurate motion.
נושאTopic 4

קפיץSpring

קפיץ וריסוןA spring and damping

  • חוק הוק: F = -k × מתיחהHooke's law: F = -k × stretch
  • ריסון: vel *= 0.98damping: vel *= 0.98
  • תנודה שדועכתAn oscillation that dies down

אנלוגיהAnalogy

ריסון הוא כמו נדנדה בגן: אם אף אחד לא דוחף, היא מתנדנדת פחות ופחות עד שהיא נעצרת.Damping is like a playground swing: if nobody pushes, it swings less and less until it stops.
נושאTopic 5

מסלולOrbit

מסלול כוכב לכתA planet's orbit

  • כבידה בין שני גופים: G·M / r²Gravity between two bodies: G·M / r²
  • הכיוון: אל השמשThe direction: toward the sun
  • אנרגיה צריכה להישמרEnergy should stay constant

אנלוגיהAnalogy

מסלול הוא כמו לזרוק כדור כל כך חזק לצד, שבזמן שהוא נופל, האדמה מתעקלת מתחתיו, והוא אף פעם לא מגיע אליה.An orbit is like throwing a ball so hard sideways that while it falls, the Earth curves away beneath it, and it never lands.
נושאTopic 6

מעבדהLab

Physics Lab: מעבדה בחלוןPhysics Lab: a lab in a window

  • כדורים עם כבידה, קירות והתנגשויותBalls with gravity, walls and collisions
  • צבע לפי מהירותColour by speed
  • מוני אנרגיה על המסךEnergy readouts on screen

אנלוגיהAnalogy

המעבדה היא כמו אקווריום: קובעים חוקים פשוטים לכל דג, ומקבלים התנהגות קבוצתית מורכבת שאף אחד לא תכנת במפורש.The lab is like an aquarium: set simple rules for each fish, and get complex group behaviour nobody programmed directly.

Vector2: חיבור, כפל, אורךVector2: add, scale, length

normalize() = כיוון באורך 1normalize() = a direction of length 1

שורה אחת במקום x ו-y בנפרדOne line instead of x and y separately

כוח → תאוצה: a = F / mForce → acceleration: a = F / m

אוילר: v += a*dt, p += v*dtEuler: v += a*dt, p += v*dt

כמה כוחות = מחברים וקטוריםSeveral forces = add the vectors

מהירות התחלתית לפי זוויתInitial velocity from an angle

סימולציה מול נוסחהSimulation vs formula

dt קטן = מדויק יותרSmaller dt = more accurate

חוק הוק: F = -k × מתיחהHooke's law: F = -k × stretch

ריסון: vel *= 0.98damping: vel *= 0.98

תנודה שדועכתAn oscillation that dies down

כבידה בין שני גופים: G·M / r²Gravity between two bodies: G·M / r²

הכיוון: אל השמשThe direction: toward the sun

אנרגיה צריכה להישמרEnergy should stay constant

כדורים עם כבידה, קירות והתנגשויותBalls with gravity, walls and collisions

צבע לפי מהירותColour by speed

מה למדנוWhat we learned

  • Vector2: חיבור, כפל, אורךVector2: add, scale, length
  • כוח → תאוצה: a = F / mForce → acceleration: a = F / m
  • מהירות התחלתית לפי זוויתInitial velocity from an angle
  • חוק הוק: F = -k × מתיחהHooke's law: F = -k × stretch
  • כבידה בין שני גופים: G·M / r²Gravity between two bodies: G·M / r²
  • כדורים עם כבידה, קירות והתנגשויותBalls with gravity, walls and collisions

עכשיו לתרגולNow, practice

5 תרגילים ו-2 אתגרים, עם בדיקה אוטומטית5 exercises and 2 challenges, auto-checked
הערות מרצהSpeaker notes

נבנה על ידיBuilt by Ariel Yohimovich