plot arrow in polarplot() (not cartesian axes)

조회 수: 24 (최근 30일)
Jack Supple
Jack Supple 2018년 4월 9일
댓글: Xiaoyu Zhao 2021년 1월 6일
I need help to draw an arrow to a polar plot (e.g. to indicate resultant vector).
I am using the new polarplot() function as opposed to the old polar() or polarhistogram() functions. Thus I cannot (to my knowledge) use functions like quiver because this would be plotted onto cartesian axes (the polarplot() function, unlike polar(), actually uses polar axes, and you can't mix up cartesian and polar child axes, as far as I know).
As far as I can see, possible solutions would be:
1. simulate an arrow by calculating and drawing an arrow shape from lots of little lines using the polarplot() function, or
2. somehow merging cartesian and polar children plots onto the same figure (if this is possible) to make use of older arrow functions (e.g. quiver or compass).
This post seeks any better suggestions, and/or solutions to the above.
Thanks!
N.B. The choice to use the polarplot() function was based on better control of axis appearance (which you don't seem to get with polar() function), and better control of histogram bar aesthetics (which you don't seem to get with polarhistogram() function...)

채택된 답변

Jack Supple
Jack Supple 2018년 4월 10일
I ended up using method 1 in the question (1. simulate an arrow by calculating and drawing an arrow shape from lots of little lines using the polarplot() function). It seems to work alright, I'm sure there must be better methods. Posting code for others
polar plot arrow
%%%Data %%%%
resultant_direction = rand(1)*2*pi;
resultant_length = 0.5 + (1-0.5).*rand(1);
%%%%arrow head %%%%
arrowhead_length = resultant_length/15; % arrow head length relative to resultant_length
num_arrowlines = 100;
arrowhead_angle = deg2rad(30); % degrees
%%%%arrow tip coordinates %%%%
t1 = repmat(resultant_direction,1,num_arrowlines);
r1 = repmat(resultant_length,1,num_arrowlines);
%%%%arrow base coordinates %%%%
b = arrowhead_length.*tan(linspace(0,arrowhead_angle,num_arrowlines/2));
theta = atan(b./(resultant_length-arrowhead_length));
pre_t2 = [theta, -theta];
r2 = (resultant_length-arrowhead_length)./cos(pre_t2);
t2 = t1(1)+pre_t2;
%%%%plot %%%%
figure(1)
polarplot([t1(1) t1(1)],[0 r1(1)-0.9*arrowhead_length],'r','linewidth',3)
hold on
polarplot([t1; t2],[r1; r2],'r')
  댓글 수: 1
Xiaoyu Zhao
Xiaoyu Zhao 2021년 1월 6일
Well done and thanks for your solution!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by