working on recipes
This commit is contained in:
parent
64b8e15918
commit
45747e3635
File diff suppressed because one or more lines are too long
214
examples/recipes.ipynb
Normal file
214
examples/recipes.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -9,6 +9,16 @@ plot!(recipe::PlotRecipe, args...; kw...) = plot!(getRecipeXY(recipe)..., args..
|
||||
plot!(plt::Plot, recipe::PlotRecipe, args...; kw...) = plot!(getRecipeXY(recipe)..., args...; getRecipeArgs(recipe)..., kw...)
|
||||
|
||||
|
||||
# -------------------------------------------------
|
||||
|
||||
function rotate(x::Real, y::Real, θ::Real; center = (0,0))
|
||||
cx = x - center[1]
|
||||
cy = y - center[2]
|
||||
xrot = cx * cos(θ) - cy * sin(θ)
|
||||
yrot = cy * cos(θ) + cx * sin(θ)
|
||||
xrot + center[1], yrot + center[2]
|
||||
end
|
||||
|
||||
# -------------------------------------------------
|
||||
|
||||
type EllipseRecipe <: PlotRecipe
|
||||
@ -22,24 +32,21 @@ EllipseRecipe(w,h,x,y) = EllipseRecipe(w,h,x,y,0)
|
||||
|
||||
# return x,y coords of a rotated ellipse, centered at the origin
|
||||
function rotatedEllipse(w, h, x, y, θ, rotθ)
|
||||
# coord before rotation
|
||||
# # coord before rotation
|
||||
xpre = w * cos(θ)
|
||||
ypre = h * sin(θ)
|
||||
|
||||
# rotate
|
||||
xrot = xpre * cos(rotθ) + ypre * sin(rotθ)
|
||||
yrot = ypre * cos(rotθ) - xpre * sin(rotθ)
|
||||
|
||||
# translate
|
||||
xrot + x, yrot + y
|
||||
# rotate and translate
|
||||
r = rotate(xpre, ypre, rotθ)
|
||||
x + r[1], y + r[2]
|
||||
end
|
||||
|
||||
function getRecipeXY(ep::EllipseRecipe)
|
||||
x, y = unzip([rotatedEllipse(ep.w, ep.h, ep.x, ep.y, u, ep.θ) for u in linspace(0,2π,100)])
|
||||
right = rotatedEllipse(ep.w, ep.h, ep.x, ep.y, 0, ep.θ)
|
||||
top = rotatedEllipse(ep.w, ep.h, ep.x, ep.y, 0.5π, ep.θ)
|
||||
linex = Float64[top[1], ep.x, right[1]]
|
||||
liney = Float64[top[2], ep.y, right[2]]
|
||||
top = rotate(0, ep.h, ep.θ)
|
||||
right = rotate(ep.w, 0, ep.θ)
|
||||
linex = Float64[top[1], 0, right[1]] + ep.x
|
||||
liney = Float64[top[2], 0, right[2]] + ep.y
|
||||
Any[x, linex], Any[y, liney]
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user