Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit vectors #51

Open
morningglory05 opened this issue Jul 12, 2022 · 4 comments
Open

unit vectors #51

morningglory05 opened this issue Jul 12, 2022 · 4 comments

Comments

@morningglory05
Copy link

@jverzani
Hi, thank you so much for creating this. I am currently using the arrow! function for 3D vectors. I did change the function since I needed to be able to specify a plot I wanted it on:
image

I want to have vectors with uniform length. However, though normalizing the vectors changes the length (these vectors are pretty short and would be invisible without the normalization), they are not uniform.
image

My understanding of the arrow! code is that normalizing the vectors should work. However, I've only recently started coding. I'm not sure where I'm going wrong here. Thanks for any advice you give.

@jverzani
Copy link
Owner

If I had to guess, I'd hazard one that the scales of the x-y-z axes are not the same. In an x-y plot, we have the aspect_ratio=:equal setting, but if memory serves, that doesn't work in 3 dimensions. You could try limiting the plotting volume to see if things look more uniform then.

BTW, I should have that extra argument to arrow!. Let's leave this issue open.

@morningglory05
Copy link
Author

You are completely right that the scales aren't equal. I can't believe I missed that! Thanks!

@jverzani
Copy link
Owner

I was off to fix this in the package, and find it has already been done:

function arrow!(plt, p, v; kwargs...)
  if length(p) == 2
      Plots.quiver!(plt, unzip([p])..., quiver=Tuple(unzip([v])); kwargs...)
  elseif length(p) == 3
      # 3d quiver needs support
      # https://github.com/JuliaPlots/Plots.jl/issues/319#issue-159652535
      # headless arrow instead
      #Plots.plot!(plt, unzip(p, p+v)...; kwargs...)
      ## use the above instead
      arrow3d!(plt, unzip(p,p+v)...; kwargs...)
  end
end
arrow!(p,v; kwargs...) = arrow!(Plots.current(), p, v; kwargs...)

Did you get code you copied from the notes? (If so, I got to fix those up...)

@morningglory05
Copy link
Author

Yeah, I got it from the notes. I'm glad its all fixed up now. Thanks again for the quick and helpful responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants