0
中心のx、y座標、
幅、及び2つの矩形の高さを入力するようにユーザを促し、第二矩形が内部 であるか否かを判断するPythonプログラムを書きます次の図に示すように、先頭または最初の矩形と重複するか、最初の矩形の外側に重なる(重複しない) です。すべての3つのケースをカバーするように、 プログラムをテストしてください。長方形/コンプレックスフロートエラー/パイソン
'Type': '>' 'complex'と 'float'のインスタンス間でサポートされていないため、修正方法がわかりません。
def main():
Center1X = eval(input("Please enter rectangle #1's center x-coordinate: "))
Center1Y = eval(input("Please enter rectangle #1's center y-coordinate: "))
Width1 = eval(input("Please enter rectangle #1's width: "))
Height1 = eval(input("Please enter rectangle #1's height: "))
Center2X = eval (input("Please enter rectangle #2's center x-coordinate: "))
Center2Y = eval(input("Please enter rectangle #2's center y-coordinate: "))
Width2 = eval(input("Please enter rectangle #2's width: "))
Height2 = eval (input("Please enter rectangle #2's height: "))
Distance_X1X2 = (Center1X**2 - Center2X**2)**0.5
Distance_Y1Y2 = (Center2Y**2 - Center2Y**2)**0.5
DistanceWidth = (Width1/2) + (Width2/2)
DistanceHeight = (Height1/2) + (Height2/2)
if (Distance_X1X2 > DistanceWidth):
print ("The Result is : Rectangle2 does not overlap Rectangle1")
elif (Distance_Y1Y2 > DistanceHeight):
print ("The Result is : Rectangle2 does not overlap Rectangle1")
elif Distance_X1X2 < DistanceWidth and Distance_Y1Y2 < DistanceHeight :
print("The Result is :Rectangle2 is inside Rectangle1.")
else:
print("The Result is :Rectangle2 overlaps Rectangle1")