1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-11-08 22:21:08 +00:00
ReCo.jl/graphics/center_of_mass.jl

123 lines
2.6 KiB
Julia
Raw Normal View History

2021-12-02 22:13:54 +00:00
using Luxor
2021-12-03 13:16:35 +00:00
using ReCo: restrict_coordinate, project_to_unit_circle, project_back_from_unit_circle
2021-12-02 22:13:54 +00:00
##
box_length = 100
box_height = 100
L = 0.35 * box_length
R = 0.35 * box_length
A = -0.9 * L
B = 0.65 * L
pr = 0.03 * L
2021-12-03 13:16:35 +00:00
Ap_array = project_to_unit_circle(A, L)
Bp_array = project_to_unit_circle(B, L)
for p in (Ap_array, Bp_array)
p[2] *= -1
end
Ap = Point(Ap_array)
Bp = Point(Bp_array)
2021-12-02 22:13:54 +00:00
M = R * ((Ap + Bp) / 2)
θ = atan(-M[2], M[1])
2021-12-03 13:16:35 +00:00
COM = project_back_from_unit_circle(θ, L)
2021-12-02 22:13:54 +00:00
COMp = R * Point(cos(θ), -sin(θ))
##
graphics_export_dir = "exports/graphics"
mkpath(graphics_export_dir)
Drawing(box_length, box_height, "$graphics_export_dir/line.pdf")
origin()
setcolor("black")
arrow(Point(-1.1 * L, 0), Point(1.2 * L, 0); arrowheadlength=0.1 * L, linewidth=0.8)
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)
setline(0.8)
line(Point(-L, 0), Point(L, 0), :stroke)
setcolor("red")
setline(0.5)
2021-12-03 02:07:07 +00:00
for x in (-L, L)
2021-12-02 22:13:54 +00:00
line(Point(x, 0.05 * L), Point(x, -0.05 * L), :stroke)
end
setcolor("cyan3")
line(Point(0, 0.05 * L), Point(0, -0.05 * L), :stroke)
setcolor("blue")
2021-12-03 02:07:07 +00:00
for p in (A, B)
2021-12-02 22:13:54 +00:00
circle(Point(p, 0), pr, :fill)
end
setcolor("brown")
circle(Point(COM, 0), pr, :fill)
setcolor("black")
fontsize(5)
text("x", Point(1.2 * L, 0.035 * L))
text("-L", Point(-L - 0.08 * L, 0.18 * L))
text("0", Point(0 - 0.035 * L, 0.18 * L))
text("+L", Point(L - 0.08 * L, 0.18 * L))
text("A", Point(A - 0.04 * L, -0.06 * L))
text("B", Point(B - 0.04 * L, -0.06 * L))
text("COM", Point(COM - 0.125 * L, -0.06 * L))
finish()
##
Drawing(box_length, box_height, "$graphics_export_dir/circle.pdf")
origin()
arrow(Point(-1.2 * R, 0), Point(1.2 * R, 0); arrowheadlength=0.1 * R, linewidth=0.8)
arrow(Point(0, 1.2 * R), Point(0, -1.2 * R); arrowheadlength=0.1 * R, linewidth=0.8)
setcolor("black")
fontsize(5)
text("α", Point(1.22 * R, 0.035 * R))
text("β", Point(-0.04 * R, -1.23 * R))
orange_green = blend(Point(0, -R), Point(0, R), "green", "orange")
setblend(orange_green)
setline(0.8)
circle(Point(0, 0), R, :stroke)
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)
setcolor("blue")
2021-12-03 02:07:07 +00:00
for pp in (Ap, Bp)
2021-12-02 22:13:54 +00:00
circle(R * pp, pr, :fill)
end
setcolor("black")
setdash("dot")
line(R * Ap, R * Bp, :stroke)
line(Point(0, 0), COMp, :stroke)
setcolor("purple1")
circle(M, pr, :fill)
setcolor("brown")
circle(COMp, pr, :fill)
finish()