通過x軸(水平軸)瞭解兩個矩形的中心和它們的角度,在Matlab中如何識別它們的交點是否爲零?任何包含這些信息的答案都是非常感謝的矩形的寬度和長度也是已知的如果matlab中兩個矩形的交點爲零
0
A
回答
0
這是一個編程問題,如果你想解決它的數值。對於確切的解決方案,您可以使用幾何方程。
第一個問題:從它的寬度,高度和中心限定一矩形的角落:
C1 = [0, 0]; % Centre of rectangle 1 (x,y)
C2 = [1, 1]; % Centre of rectangle 2 (x,y)
W1 = 5; W2 = 3; % Widths of rectangles 1 and 2
H1 = 2; H2 = 3; % Heights of rectangles 1 and 2
% Define the corner points of the rectangles using the above
R1 = [C1(1) + [W1; W1; -W1; -W1]/2, C1(2) + [H1; -H1; -H1; H1]/2];
R2 = [C2(1) + [W2; W2; -W2; -W2]/2, C2(2) + [H2; -H2; -H2; H2]/2];
接下來的問題是創造許多點代表矩形的邊緣。如果您想查看相交區域,則可以在內生成許多點。
n = 1000; % Define some number of points to use
% Use interp1 to interpolate around the rectangles
R1points = interp1(1:5, [R1; R1(1,:)], linspace(1,5,n));
R2points = interp1(1:5, [R2; R2(1,:)], linspace(1,5,n));
然後旋轉矩形:
a1 = deg2rad(0); a2 = deg2rad(30); % angles of rotation for rectangle 1 and 2 respectively
R1rotated(:,1) = (R1points(:,1)-C1(1))*cos(a1) - (R1points(:,2)-C1(2))*sin(a1) + C1(1);
R1rotated(:,2) = (R1points(:,1)-C1(1))*sin(a1) + (R1points(:,2)-C1(2))*cos(a1) + C1(2);
R2rotated(:,1) = (R2points(:,1)-C2(1))*cos(a2) - (R2points(:,2)-C2(2))*sin(a2) + C2(1);
R2rotated(:,2) = (R2points(:,1)-C2(1))*sin(a2) + (R2points(:,2)-C2(2))*cos(a2) + C2(2);
最後,檢查交叉口inpolygon
:
in1 = inpolygon(R1rotated(:,1), R1rotated(:,2), R2rotated(:,1), R2rotated(:,2));
in2 = inpolygon(R2rotated(:,1), R2rotated(:,2), R1rotated(:,1), R1rotated(:,2));
如果nnz(in1)>0
或nnz(in2)>0
那麼你有一個交集!使用分散它想象:
hold on
scatter(R2rotated(:,1), R2rotated(:,2), '.b')
scatter(R2rotated(in2,1), R2rotated(in2,2), 'xc')
scatter(R1rotated(:,1), R1rotated(:,2), '.r')
scatter(R1rotated(in1,1), R1rotated(in1,2), 'xg')
結果:
相關問題
- 1. 零高矩形包含點
- 2. 在Matlab中繪製無交點區域的透明矩形
- 3. 如何在matlab中的兩個矩陣之間進行單點交叉
- 4. MATLAB中兩個圓相交點
- 5. Java矩形的交點
- 6. 矩形的交叉點java
- 7. 矩形的交點問題
- 8. 檢查兩個矩形之間的交點?
- 9. 如何將SURF點矩陣轉換爲Matlab中的兩倍
- 10. Matlab:兩條線的交點
- 11. MATLAB:兩個圓錐曲線的交點
- 12. 如何在Matlab中計算大型稀疏矩陣的零點?
- 13. XNA矩形交叉點
- 14. 在鄰接矩陣中形成一個循環的節點(Matlab)
- 15. Python稀疏矩陣非零值交點
- 16. 處理平臺遊戲中的兩個矩形的交集
- 17. 如何在matlab中得到直線矩形相交線段
- 18. 如何從兩點創建矩形?
- 19. 爲什麼Rect.Intersect爲兩個不相交的矩形返回一個非空Rect?
- 20. 在wxpython中繪製一個帶有兩個點的矩形
- 21. 如何使用Matlab或Excel從兩個表中獲得交點?
- 22. MATLAB交換兩個不同矩陣的列
- 23. 兩個矩形之間的差異(XOR),如矩形?
- 24. 非軸對齊的矩形交叉點
- 25. 獲取矩形和線的交點
- 26. 線與矩形之間的交點
- 27. C#矩形相交錯誤的結果點
- 28. 在Matlab中比較兩個矩陣
- 29. 在Matlab中連接兩個矩陣
- 30. 在matlab圖上交互操縱一個矩形
這是一個數學問題不是一個問題MATLAB。 –
但我想通過matlab @AnderBiguri解決它你知道我能做什麼嗎? –
首先找出數學問題,然後來到這裏,描述它並告訴我們你有什麼編程問題。我在紙上寫數學,但是我沒有要求紙業公司尋求解決方案,因爲我在紙上做這件事並不意味着它是紙面問題。用MATLAB替換紙張。 –