1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-09-19 19:01:17 +00:00
ReCo.jl/graphics/center_of_mass.jl

130 lines
3.2 KiB
Julia
Raw Normal View History

2021-12-02 22:13:54 +00:00
using Luxor
2022-01-25 02:12:45 +00:00
using ReCo: ReCo
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
function gen_COM_graphics()
box_length = 100
box_height = 100
2021-12-02 22:13:54 +00:00
2022-01-29 00:04:51 +00:00
L = 0.39 * box_length
2021-12-02 22:13:54 +00:00
2022-01-29 00:04:51 +00:00
R = 0.37 * box_length
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
A = -0.9 * L
B = 0.65 * L
2022-01-29 00:04:51 +00:00
particle_radius = 0.05 * L
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
Ap_vec = Vector(ReCo.Shape.project_to_unit_circle(A, L))
Bp_vec = Vector(ReCo.Shape.project_to_unit_circle(B, L))
for p in (Ap_vec, Bp_vec)
p[2] *= -1
end
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
Ap = Point(Ap_vec[1], Ap_vec[2])
Bp = Point(Bp_vec[1], Bp_vec[2])
2021-12-03 13:16:35 +00:00
2022-01-25 02:12:45 +00:00
M = R * ((Ap + Bp) / 2)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
θ = atan(-M[2], M[1])
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
COM = ReCo.Shape.project_back_from_unit_circle(θ, L)
si, co = sincos(θ)
COMp = R * Point(co, -si)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
##
2021-12-02 22:13:54 +00:00
2022-01-25 04:12:17 +00:00
graphics_export_dir = "exports/graphics/COM"
2022-01-25 02:12:45 +00:00
mkpath(graphics_export_dir)
2021-12-02 22:13:54 +00:00
2022-01-25 04:12:17 +00:00
Drawing(box_length, box_height, "$graphics_export_dir/linear.pdf")
2022-01-25 02:12:45 +00:00
origin()
2022-01-29 00:04:51 +00:00
fontsize(5)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("black")
2022-01-29 00:04:51 +00:00
arrow(Point(-1.1 * L, 0), Point(1.2 * L, 0); arrowheadlength=0.1 * L, linewidth=1.0)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
green_orange = blend(Point(-1.5 * L, 0), Point(1.5 * L, 0))
addstop(green_orange, 0.0, "orange")
addstop(green_orange, (L) / (3 * L), "green")
addstop(green_orange, (2 * L) / (3 * L), "orange")
addstop(green_orange, 1.0, "green")
setblend(green_orange)
2022-01-29 00:40:57 +00:00
setline(1.0)
2022-01-25 02:12:45 +00:00
line(Point(-L, 0), Point(L, 0), :stroke)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("red")
setline(0.5)
for x in (-L, L)
line(Point(x, 0.05 * L), Point(x, -0.05 * L), :stroke)
end
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("cyan3")
line(Point(0, 0.05 * L), Point(0, -0.05 * L), :stroke)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("blue")
for p in (A, B)
2022-01-29 00:04:51 +00:00
circle(Point(p, 0), particle_radius, :fill)
2022-01-25 02:12:45 +00:00
end
2022-01-29 00:04:51 +00:00
text("A", Point(A - 0.030 * L, -0.08 * L))
text("B", Point(B - 0.030 * L, -0.08 * L))
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("brown")
2022-01-29 00:04:51 +00:00
circle(Point(COM, 0), particle_radius, :fill)
text("COM", Point(COM - 0.098 * L, -0.08 * L))
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("black")
text("x", Point(1.2 * L, 0.038 * L))
2022-01-29 00:04:51 +00:00
text("-L/2", Point(-L - 0.15 * L, 0.20 * L))
text("0", Point(0 - 0.030 * L, 0.18 * L))
text("+L/2", Point(L - 0.15 * L, 0.20 * L))
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
finish()
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
##
2021-12-02 22:13:54 +00:00
2022-01-25 04:12:17 +00:00
Drawing(box_length, box_height, "$graphics_export_dir/circular_projectiong.pdf")
2022-01-25 02:12:45 +00:00
origin()
2022-01-29 00:04:51 +00:00
fontsize(5)
2021-12-02 22:13:54 +00:00
2022-01-29 00:04:51 +00:00
arrow(Point(-1.2 * R, 0), Point(1.2 * R, 0); arrowheadlength=0.1 * R, linewidth=1.0)
arrow(Point(0, 1.2 * R), Point(0, -1.2 * R); arrowheadlength=0.1 * R, linewidth=1.0)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("black")
text("α", Point(1.22 * R, 0.035 * R))
text("β", Point(-0.04 * R, -1.23 * R))
2021-12-02 22:13:54 +00:00
2022-01-29 00:40:57 +00:00
green_orange = blend(Point(0, -R), Point(0, R), "green", "orange")
setblend(green_orange)
2022-01-29 00:04:51 +00:00
setline(1.0)
2022-01-25 02:12:45 +00:00
circle(Point(0, 0), R, :stroke)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("red")
setline(0.5)
line(Point(1.05 * R, 0), Point(0.95 * R, 0), :stroke)
setcolor("cyan3")
line(Point(-1.05 * R, 0), Point(-0.95 * R, 0), :stroke)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("blue")
for pp in (Ap, Bp)
2022-01-29 00:04:51 +00:00
circle(R * pp, particle_radius, :fill)
2022-01-25 02:12:45 +00:00
end
2022-01-29 00:04:51 +00:00
text("A", 1.07 * R * Ap)
text("B", 1.14 * R * Bp)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("black")
setdash("dot")
line(R * Ap, R * Bp, :stroke)
line(Point(0, 0), COMp, :stroke)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("purple1")
2022-01-29 00:04:51 +00:00
circle(M, particle_radius, :fill)
text("COM'", 0.019 * R * M + R * Point(0.0, -0.04))
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
setcolor("brown")
2022-01-29 00:04:51 +00:00
circle(COMp, particle_radius, :fill)
text("S", 0.029 * R * COMp)
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
finish()
2021-12-02 22:13:54 +00:00
2022-01-25 02:12:45 +00:00
return nothing
end