ScriptSpot

Forum topic · General Scripting

Mirror Position problem

By Ishak Suryo Laksono · 2009-09-22

Description

Hi All...i've got serious problem here.I try to create mirror data based on the vertex position. The problem is: why my script only works on simple geometry?when i run on the higher geometry (above 1000 vertex) it still running but the result is not like my expectation.Here is my script...its only work for mirror x in worldspace for now.there is 2 version,the one is working an another is not.yo can check manually that the position each vertex is exactly have a mirror.
thanks for all feedbacks...

---------working-------------
--Create box simple
mybox=box lengthsegs:1 widthsegs:1 heightsegs:1
convertto mybox editable_poly

select mybox
-- Collect position data
position=for i in $.Verts collect i.pos

-- Copy data for comparison
comparison= deepcopy position

-- Change each value of X in comparison
for i=1 to comparison.count do
(
comparison[i][1]=-comparison[i][1]
)

temp=#() --Create array to save mirror data

--compare
for i in position do
( c=finditem comparison i
append temp c
)
print Temp

---------working-------------

---------NOT working-------------
--"Notes:The difference is just the number of segments of the box"-------

--Create box simple
mybox=box lengthsegs:1 widthsegs:3 heightsegs:1
convertto mybox editable_poly

select mybox
-- Collect position data
position=for i in $.Verts collect i.pos

-- Copy data for comparison
comparison= deepcopy position

-- Change each value of X in comparison
for i=1 to comparison.count do
(
comparison[i][1]=-comparison[i][1]
)

temp=#() --Create array to save mirror data

--compare
for i in position do
( c=finditem comparison i
append temp c
)
print Temp

---------Not working-------------

Comments (3)

Marco Brunetta · 2009-10-13

It's a rounding error, even if the point3 look the same in the listener they are actually different by really reaaaaaaally small margin. If you manually try subtracting the two "matches" that findItem reports as different, you'll see that the result is not [0,0,0] but something like [9.53674e-007,0,0]

Ishak Suryo Laksono · 2009-10-13

Hi thanks for your feedback and sorry for to long to reply this.
i know the script is fine,but the problem is the "0" result when finding item inside the array.It should be found when we check on the print result...but why the result is always "0"

i adds a few line to show you the error...(it just the format thing) and i put image in the attachment to make it clearly.....I hope somebody can explain to solve my problem
...same as previous,the different is just the widthsegs of the box in both script:

-------------WORKING--------------
mybox=box lengthsegs:1 widthsegs:1 heightsegs:1
convertto mybox editable_poly

select mybox
-- Collect position data
position=for i in $.Verts collect i.pos

-- Copy data for comparison
comparison= deepcopy position

-- Change each value of X in comparison
for i=1 to comparison.count do
(
comparison[i][1]=-comparison[i][1]
)

temp=#() --Create array to save mirror data

--compare
for i in position do
( c=finditem comparison i
append temp c
format "finding % \n in: % \n result: % \n" i comparison c
)
print Temp
---------------------------------------

-------------NOT WORKING--------------
mybox=box lengthsegs:1 widthsegs:3 heightsegs:1
convertto mybox editable_poly

select mybox
-- Collect position data
position=for i in $.Verts collect i.pos

-- Copy data for comparison
comparison= deepcopy position

-- Change each value of X in comparison
for i=1 to comparison.count do
(
comparison[i][1]=-comparison[i][1]
)

temp=#() --Create array to save mirror data

--compare
for i in position do
( c=finditem comparison i
append temp c
format "finding % \n in: % \n result: % \n" i comparison c
)
print Temp
---------------------------------------

Attachments

Anubis · 2009-09-24

What means not works? finditem() returns item index if found and 0 if not. In the 2nd example finditem() function returns 0 for all items. Simple test:

array1 = #([1,0,0],[0,1,0],[0,0,1],[0,0,0])
array2 = deepcopy array1
for i=1 to array2.count do (array2[i][1] *= -1)
array1; array2  -- test them
temp=#()
for i in array1 do (
	c = findItem array2 i ; append temp c)
print temp -- 0, 2, 3, 4 -- the result is fine