0
我想顯示一個矩形,它的中心位於(x,y)位置,其長軸與x軸成角度φ。我怎樣才能做到這一點?使用散點圖顯示指定方向的矩形
我可以
scatter(x,y)
顯示位置(X,Y)的圓形點,但我不知道該矩形的想法。
我想顯示一個矩形,它的中心位於(x,y)位置,其長軸與x軸成角度φ。我怎樣才能做到這一點?使用散點圖顯示指定方向的矩形
我可以
scatter(x,y)
顯示位置(X,Y)的圓形點,但我不知道該矩形的想法。
使用fill
從其x
和y
座標繪製2D多邊形。
c = [0, 0]; % Position of centre
h = 5; w = 8; % height and width of rectangle
a = deg2rad(30); % angle of rotation in radians (using deg2rad so can be set in degrees)
% Get corners of rectangle
corners = [c(1) + w/2, c(2) + h/2; c(1) + w/2, c(2) - h/2; c(1) - w/2, c(2) - h/2; c(1) - w/2, c(2) + h/2];
% rotate corner points
corners = [(corners(:,1)-c(1))*cos(a) - (corners(:,2)-c(2))*sin(a) + c(1), (corners(:,1)-c(1))*sin(a) + (corners(:,2)-c(2))*cos(a) + c(2)];
% Use 'fill' or 'patch' to plot
fill(corners(:,1), corners(:,2), 'r')
這可以被包裝成一個功能,如果你想重新使用它
function [corners(:,1), corners(:,2)] = getRectangle(c, h, w, a)
% This function returns the corner points for a rectangle, specified
% by its centre point c = [x,y], height h, width w and angle in degrees from horizontal a
a = deg2rad(a);
corners = [c(1) + w/2, c(2) + h/2; c(1) + w/2, c(2) - h/2; c(1) - w/2, c(2) - h/2; c(1) - w/2, c(2) + h/2];
corners = [(corners(:,1)-c(1))*cos(a) - (corners(:,2)-c(2))*sin(a) + c(1), (corners(:,1)-c(1))*sin(a) + (corners(:,2)-c(2))*cos(a) + c(2)];
end
用途:
[rectX, rectY] = getRectangle([0,0], 5, 8, 30);
fill(rectX, rectY, 'r');
我想用散射如何大量數據,而不是情節! –
使用散射函數時,您只需要矩形點而不是圓形?這與矩形與x軸的角度有什麼關係?只需將'scatter(x,y,'d')'或'scatter(x,y,'s')放在正方形中就可以散開。 – Wolfie
使用散射函數時,您只需要矩形點而不是圓形?對,就是這樣。這與矩形與x軸的角度有什麼關係?這是我問的問題。 –