๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
6. ํฐํ ๊ทธ๋ํฝ์ผ๋ก ๊ถค์ ๊ทธ๋ฆฌ๊ธฐ โ โ์ฐ์ฃผ ๊ฒฝ์์์ ์น๋ฆฌํ๊ธฐ ์ํ ์ํด๋ก 8ํธ์ ๊ถค์ ์๋ฎฌ๋ ์ด์ โ ๋ณธ๋ฌธ
6. ํฐํ ๊ทธ๋ํฝ์ผ๋ก ๊ถค์ ๊ทธ๋ฆฌ๊ธฐ โ โ์ฐ์ฃผ ๊ฒฝ์์์ ์น๋ฆฌํ๊ธฐ ์ํ ์ํด๋ก 8ํธ์ ๊ถค์ ์๋ฎฌ๋ ์ด์ โ
์ง์ง์ํ์นด 2022. 10. 25. 16:14221025 ์์ฑ
<๋ณธ ๋ธ๋ก๊ทธ๋์ค์ ํ์ด์ฌ ํธ์ฆ์จ ํ๋ก์ ํธ์ github ๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค>
https://www.onlybook.co.kr/m/entry/python-projects
์ค์ ํ์ด์ฌ ํธ์ฆ์จ ํ๋ก์ ํธ
์ค์ ํ์ด์ฌ ํธ์ฆ์จ ํ๋ก์ ํธ ๋ฌธ์ ํด๊ฒฐ๊ณผ ์ค๋ฌด ์์ฉ๋ ฅ์ ํค์ฐ๊ธฐ ์ํ ๋๋ง์ ํ์ด์ฌ ํฌํธํด๋ฆฌ์ค ๋ง๋ค๊ธฐ ๋ฆฌ ๋ณธ ์ง์ | ์คํ์ ์ฎ๊น 420์ชฝ | 28,000์ | 2022๋ 5์ 31์ผ ์ถ๊ฐ | 185*240*20 | ISBN13 9791.
www.onlybook.co.kr
https://github.com/rlvaugh/Real_World_Python
GitHub - rlvaugh/Real_World_Python: Code and supporting files for book Real World Python
Code and supporting files for book Real World Python - GitHub - rlvaugh/Real_World_Python: Code and supporting files for book Real World Python
github.com
๐ฅ turtle ๋ชจ๋ ํ์ฉ
: ์ํํ ๋๋ฐ์ ์ฐธ์ฌํด ๋ฏธ๊ตญ์ ์ํด๋ก 8ํธ๊ฐ ๋ฌ ์ฐฉ๋ฅ ๊ฒฝ์์์ ์น๋ฆฌํ ์ ์๋๋ก ๋๋๋ค
: ๋ฏธ ํญ๊ณต์ฐ์ฃผ๊ตญ ๋์ฌ(NASA)๊ฐ ์์๋ณด๋ค 1๋ ์ด๋ ๋ ์ผ์ฐ ๋ฌ ๊ถค๋์ ๋์ฐฉํด์ ์๋ จ์ด ์ค์ง์ ์ผ๋ก ๋ฌ ์ฐฉ๋ฅ ํ๋ก๊ทธ๋จ์ ํฌ๊ธฐํ๊ฒ ๋ง๋ , ๋๋ํ ์์ ๊ทํ ๋นํ ๊ถค์ ์ ๊ทธ๋ฆผ์ผ๋ก ๊ทธ๋ ค์ ์คํํด๋ณธ๋ค
from turtle import Shape, Screen, Turtle, Vec2D as Vec
import turtle
import math
# User input:
G = 8 # ์๋ฎฌ๋ ์ด์
์ ์ฌ์ฉ๋๋ ์ค๋ ฅ ์์
NUM_LOOPS = 4100 # ์๋ฎฌ๋ ์ด์
์ ์๊ฐ ๋จ๊ณ ์
Ro_X = 0 # ์ ๋ฐ ์์ ์์น x ์ขํ
Ro_Y = -50 # ์ ๋ฐ ์์ ์์น y ์ขํ
Vo_X = 0 # ์ ๋ฐ ์๋ x ๊ตฌ์ฑ ์์
Vo_Y = 0 # ์ ๋ฐ ์๋ y ๊ตฌ์ฑ ์์
MOON_MASS = 1_250_000
class GravSys():
"""n-๋ฐ๋์์ ์ค๋ ฅ ์๋ฎฌ๋ ์ด์
์ ์คํ"""
def __init__(self):
self.bodies = []
self.t = 0
self.dt = 0.001
def sim_loop(self):
"""์๊ฐ ๋จ๊ณ๋ฅผ ํตํด ๋ชฉ๋ก์์ ๋ณธ๋ฌธ์ ๋ฐ๋ณต"""
for _ in range(NUM_LOOPS):
self.t += self.dt
for body in self.bodies:
body.step()
class Body(Turtle):
"""์ค๋ ฅ์ฅ์ ๊ณต์ ํ๊ณ ํฌ์ํ๋ ์ฒ์ฒด"""
def __init__(self, mass, start_loc, vel, gravsys, shape):
super().__init__(shape=shape)
self.gravsys = gravsys
self.penup()
self.mass=mass
self.setpos(start_loc)
self.vel = vel
gravsys.bodies.append(self)
self.pendown() # ๊ฐ์ฒด ๋ค์ ๊ฒฝ๋ก๋ฅผ ๊ทธ๋ฆฌ๋ ์ฃผ์ ์ ๊ฑฐ
def acc(self):
"""๋ชธ์ฒด์ ์์ฉํ๋ ํ์ ๊ณ์ฐํ๊ณ ๋ฒกํฐ ๊ตฌ์ฑ ์์๋ฅผ ๋ฐํ"""
a = Vec(0,0)
for body in self.gravsys.bodies:
if body != self:
r = body.pos() - self.pos()
a += (G * body.mass / abs(r)**3) * r # ๋จ์ dist /time^2
return a
def step(self):
"""๋ชธ์ฒด์ ์์น, ๋ฐฉํฅ ๋ฐ ์๋๋ฅผ ๊ณ์ฐ"""
dt = self.gravsys.dt
a = self.acc()
self.vel = self.vel + dt * a
xOld, yOld = self.pos() # ๋ฐฐ๋ฅผ ๋ฐฐํฅํ๊ธฐ ์ํด
self.setpos(self.pos() + dt * self.vel)
xNew, yNew = self.pos() # ๋ฐฐ๋ฅผ ๋ฐฐํฅํ๊ธฐ ์ํด
if self.gravsys.bodies.index(self) == 1: # the CSM
dir_radians = math.atan2(yNew-yOld,xNew-xOld) # ๋ฐฐ๋ฅผ ๋ฐฐํฅํ๊ธฐ ์ํด
dir_degrees = dir_radians * 180 / math.pi # ๋ฐฐ๋ฅผ ๋ฐฐํฅํ๊ธฐ ์ํด
self.setheading(dir_degrees+90) # ๋ฐฐ๋ฅผ ๋ฐฐํฅํ๊ธฐ ์ํด
def main():
# ์ค์ ํ๋ฉด
screen = Screen()
screen.setup(width = 1.0, height = 1.0) # ์ ์ฒดํ๋ฉด์ฉ
screen.bgcolor('black')
screen.title("Gravity Assist Example")
# ์ค๋ ฅ ์์คํ
์ธ์คํด์คํ
gravsys = GravSys()
# ํ์ฑ ์ธ์คํด์คํ
image_moon = 'moon_27x27.gif'
screen.register_shape(image_moon)
moon = Body(MOON_MASS, (500, 0), Vec(-500, 0), gravsys, image_moon)
moon.pencolor('gray')
# ์ปค๋งจ๋-์๋น์ค-๋ชจ๋(csm) ํํ๋ฅผ ๊ตฌ์ถ
csm = Shape('compound')
cm = ((0, 30), (0, -30), (30, 0))
csm.addcomponent(cm, 'red', 'red')
sm = ((-60,30), (0, 30), (0, -30), (-60, -30))
csm.addcomponent(sm, 'red', 'black')
nozzle = ((-55, 0), (-90, 20), (-90, -20))
csm.addcomponent(nozzle, 'red', 'red')
screen.register_shape('csm', csm)
# Apollo 8 CSM ๊ฑฐ๋ถ์ด ์ธ์คํด์คํ
ship = Body(1, (Ro_X, Ro_Y), Vec(Vo_X, Vo_Y), gravsys, "csm")
ship.shapesize(0.2)
ship.color('red') # path color
ship.getscreen().tracer(1, 0)
ship.setheading(90)
gravsys.sim_loop()
if __name__=='__main__':
main()
'๐ฉโ๐ป IoT (Embedded) > Image Processing' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
OpenCV ๊ทธ๋ฆฌ๊ธฐ ํจ์ ์, ์ฌ๊ฐํ, ์ง์ , ๋ค๊ฐํ, ๋ฌธ์์ด (0) | 2022.11.07 |
---|---|
๊ฐ์ฒด ํ์ง Object Detection ์ฃผ์ ๋ชจ๋ธ one stage & two stage (0) | 2022.11.07 |
OpenCV์ ์ ์ฉํ๋ ๋ง์คํฌ ์ฐ์ฐ๊ณผ ROI (0) | 2022.10.20 |
OpenCV ์์ ๋ฐ์ดํฐ ๊ตฌ์กฐ + ์์ฑ, ๋ณต์ฌ, ๋ถ๋ถ ์ถ์ถ (0) | 2022.10.20 |
OpenCV๋ก ์ด๋ฏธ์ง ์ฌ๋ผ์ด๋์ผ ๋ง๋ค๊ธฐ (0) | 2022.10.20 |