通过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替换纸张。 –