我正在创建一个脚本来确定形状是否已经变形或缩放。首先列出一个形状的线条的所有长度,如下所示。
set noofsides to text returned of (display dialog "Enter number of sides:" default answer "")
set sidevalues to {}
set repeatnumber to 0
repeat noofsides times
set repeatnumber to repeatnumber + 1
set currentsidevalue to text returned of (display dialog "Enter length of line " & repeatnumber & ":" default answer "")
set the end of sidevalues to currentsidevalue
end repeat
然后对第二个已编辑的形状执行相同的操作。这给了我两个包含不同变量的列表。为了确定两个形状是否相似,每个“前”行除以每个“后”行必须相同。例如,对于三角形:
firstline1/secondline1 = firstline2/secondline2 = firstline3/secondline3
有没有办法快速完成此操作而无需执行以下操作:
try
set primevariable1 to first item of primesidevalues
set primevariable2 to second item of primesidevalues
set primevariable3 to third item of primesidevalues
-- ...
end try
try
set regularvariable1 to first item of sidevalues
set regularvariable2 to second item of sidevalues
set regularvariable3 to third item of sidevalues
-- ...
end try
try
variable4
on error
set variable4 to ""
end try
if (regularvariable1 / primevariable1) = (regularvariable2 / primevariable2) and (regularvariable3 / primevariable3) = (regularvariable1 / primevariable1) and (regularvariable3 / primevariable3) = (regularvariable2 / primevariable2) and variable4 = "" then
display dialog "Shape is similar"
end if
仅适用于3面形状。如果我想用5或6个方面做某事,这将变得越来越长。或许如果将列表中的每个数字除以列表2中的每个数字都相等,那么形状是否相似?有人可以帮忙吗?
答案 0 :(得分:0)
获取(第一个列表中的第一个项目 /
第二个列表中的第一个项目)的值,使用循环来比较值其他项目,如下:
set sidevalues to my getSidesValue("Enter number of sides for the first shape:")
set primesidevalues to my getSidesValue("Enter number of sides for the second shape:")
set tc to count sidevalues
if tc = (count primesidevalues) then -- the number of items in the lists is the same
set isSimilar to true
set thisVal to (item 1 of sidevalues) / (item 1 of primesidevalues) -- Get the value of the first item in the lists
repeat with i from 2 to tc -- loop to compare the value of the others items
if (item i of sidevalues) / (item i of primesidevalues) is not thisVal then -- not the same value
set isSimilar to false
exit repeat -- no need to continue
end if
end repeat
else
set isSimilar to false
end if
isSimilar
on getSidesValue(t)
set noofsides to text returned of (display dialog t default answer "")
set l to {}
repeat with i from 1 to noofsides
set currentsidevalue to text returned of (display dialog "Enter length of line " & i & ":" default answer "")
set the end of l to currentsidevalue
end repeat
return l
end getSidesValue