Makie.jl icon indicating copy to clipboard operation
Makie.jl copied to clipboard

Add origin to Transformation

Open ffreyer opened this issue 4 months ago • 4 comments

Description

Related: #4445, #2637

This adds an origin to Transformation so that rotate!() and scale!() can be relative to something other than Vec3(0). It can be set with translate_origin!() just like translate!().

Example:

p = rand(Point2f)
rect = Rect2f(p .- 0.1, Vec2f(0.2))

fig = Figure()
sl = Slider(fig[1, 1], range = range(0, 2pi, length=101))
ax = Axis(fig[2, 1], aspect = DataAspect())
p1 = poly!(ax, rect, color = :orange)
p2 = lines!(ax, rect, color = :red)
xlims!(ax, -1.5, 1.5)
ylims!(ax, -1.1, 1.1)

on(sl.value) do angle
    center = to_ndim(Vec3f, p, 0)

    R = Makie.rotationmatrix_z(angle)
    T = Makie.translationmatrix(-center)
    Tinv = Makie.translationmatrix(center)
    p1.transformation.model[] = Tinv * R * T # Did we break setting plot.model?
    
    translate_origin!(p2, p)
    Makie.rotate!(p2, angle)
end

fig

Type of change

  • [x] New feature (non-breaking change which adds functionality)

Checklist

  • [x] Added an entry in CHANGELOG.md (for new features and breaking changes)
  • [x] Added or changed relevant sections in the documentation
  • [x] Added unit tests for new algorithms, conversion methods, etc.
  • [ ] Added reference image tests for new plotting functions, recipes, visual options, etc.

ffreyer avatar Oct 10 '24 22:10 ffreyer