Hello,
I am trying to plot (a lot of) data in a live “polar heatmap”. A triangular visualization like below is ok.
For now I have used polygons by modifying this example:
https://docs.makie.org/stable/examples/plotting_functions/poly/
However my current solution is way to slow when I add millions of point.
I am not sure polygons like below code are the way to go, maybe someone have a tip on a more efficient way to draw something like this in GLMakie?
(overlapping triangles? something completly different?)
If anyone has suggestions it would be greatly appreciated! Thanks!
Code:
using GLMakie, GeometryBasics, BenchmarkTools, StaticArrays
function calc_polygons(start_θ_deg::Float64, end_θ_deg::Float64, amplitude::Vector{Float64})
# number of cells
n = length(amplitude)
# start point
p₀_start_az = Point2f(0, 0)
p₀_end_az = Point2f(0, 0)
# Pre-calculate sin and cos outside the loop to avoid redundant calculations.
start_θ_rad = deg2rad(start_θ_deg)
end_θ_rad = deg2rad(end_θ_deg)
(start_θ_sin, start_θ_cos) = sincos(start_θ_rad)
(end_θ_sin, end_θ_cos) = sincos(end_θ_rad)
# Pre-calculate start_θ_offset and end_θ_offset outside the loop to avoid redundant calculations.
start_θ_offset = Point2f(start_θ_cos, start_θ_sin)
end_θ_offset = Point2f(end_θ_cos, end_θ_sin)
polygons = [Polygon([
p₀_end_az + (i-1) * end_θ_offset,
p₀_start_az + (i-1) * start_θ_offset,
p₀_start_az + i * start_θ_offset,
p₀_end_az + i * end_θ_offset
]) for i in 1:n]
# convert amplitude vector to color vector
rgb_colors = [RGBf(amp,0,0) for amp in amplitude]
return (polygons, rgb_colors)
end
function main()
polygons, rgb_colors = calc_polygons(20., 30., rand(5));
poly(polygons, color = rgb_colors, overdraw = true)
end
main()