I’m having no luck finding a working example of how to define a makie @recipe for a custom type, or in this case custom types.
I have a home grown quaternion and a 3D vector type which match better how legacy simulations function making conversion better. The Vector type presents an x, y, and z field. The quaternion can rotate those vectors.
In Plots.jl recipe it is fairly easy to specify a plot overload that throws up 3 lines representing the XYZ axis of a quaternion rotation into a plot where I have an optional origin for the axis and a scale factor for the length of the axis.
The Plot.jl recipe I’m trying to emulate starts out with a from like this.
quaternion_plot
@recipe function f(q::quaternion, v::xyzVecT = xyzVecT(); scalefactor = 1.0)
# Quaternion will plot the X, Y and Z axis at the location
seriestype := :path
linestyle --> :solid
arrow --> :True
seriesalpha --> 0.4
marker --> :none
xaxis = xVec(scalefactor) * q
yaxis = yVec(scalefactor) * q
zaxis = zVec(scalefactor) * q
quickFmt(a,b) = [a.x,b.x], [a.y, b.y], [a.z, b.z]
# Plot the X Axis in Blue with reduced alpha
@series begin
label --> :none
seriescolor --> :blue
marker := :none
quickFmt(v, v + xaxis) # Remove the vector markers
end
@series begin
label --> :none
seriescolor --> :green
marker := :none
quickFmt(v, v + yaxis) # Remove the vector markers
end
@series begin
label --> :none
seriescolor --> :red
marker := :none
quickFmt(v, v + zaxis) # Remove the vector markers
end
# Direction Pointers
@series begin
label --> "X"
seriestype --> :scatter
seriescolor --> :blue
marker := :diamond
temp=v + xaxis
[temp.x], [temp.y], [temp.z]
end
@series begin
label --> "Y"
seriestype --> :scatter
seriescolor --> :green
marker := :circle
temp=v + yaxis
[temp.x], [temp.y], [temp.z]
end
@series begin
label --> "Z"
seriestype --> :scatter
seriescolor --> :red
marker := :square
temp=v + zaxis
[temp.x], [temp.y], [temp.z]
end
end
I cannot figure out how to get the Makie.@recipe to do anything, even if I skip the origin shift and the scale factor and just take the quaternion. I find just the one documentation example and a dataframe example on the internet. Can someone help me understand this @recipe concept and figure out how to use it or is it just too far off and I need to forget a recipe.
@recipe(QPlot, q, origin, scale_factor ) do scene
Attributes(
color = :red,
style = :dashed
)
end
function plot!(qp::QPlot)
xaxis = xVec(qp[:scale_factor][]) * qp[:q][]
yaxis = yVec(qp[:scale_factor][]) * qp[:q][]
zaxis = zVec(qp[:scale_factor][]) * qp[:q][]
quickFmt(a,b) = [a.x,b.x], [a.y, b.y], [a.z, b.z]
lines!(qp,quickFmt(qp[:origin], qp[:origin] + xaxis),color=qp[:color][],linestyle=qp[:style][])
lines!(qp,quickFmt(qp[:origin], qp[:origin] + yaxis),color=qp[:color][],linestyle=qp[:style][])
lines!(qp,quickFmt(qp[:origin], qp[:origin] + zaxis),color=qp[:color][],linestyle=qp[:style][])
qp
end
Note: I’m assuming the quickFmt works the same for lines! as it did for the plot recipe, but I haven’t even gotten into the function to debug any of that stuff.
Thanks for any help and understanding.
Best Regards,
Allan