Wrong transformation after convex hull

Report crashes, strange behaviour, or apparent bugs
Post Reply
Boris
Posts: 41
Joined: 14 Jun 2017, 12:40

Wrong transformation after convex hull

Post by Boris »

Hi,

When I try to compute the convex hull of an object in a child script, I notice that the original object and convex hull object do not align. I use the following code:

Code: Select all

h = sim.getObjectHandle('imported_part_0')
data = sim.getShapeViz(h, 0) 

newVertices, newFaces=sim.getQHull(data.vertices) -- get convex hull
newMeshh=sim.createMeshShape(0, 0, newVertices, newFaces)
sim.setObjectPosition(newMeshh, h, {0,0,0})
sim.setObjectOrientation(newMeshh, h, {0,0,0})
The scene with a minimal example: https://wetransfer.com/downloads/3026a9 ... 553/ce9487

Is this a bug, or am I doing something wrong?

Kind regards,
Boris

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Wrong transformation after convex hull

Post by coppelia »

Hello,

the API function sim.getShapeViz returns the vertices relative to the shape's reference frame. So following would give you correct results:

Code: Select all

function sysCall_init()
    h = sim.getObjectHandle('imported_part_0')
    data = sim.getShapeViz(h,0)
    local m=sim.getObjectMatrix(h,-1)
    for i=1,#data.vertices/3,1 do
        local v={data.vertices[3*(i-1)+1],data.vertices[3*(i-1)+2],data.vertices[3*(i-1)+3]}
        v=sim.multiplyVector(m,v)
        data.vertices[3*(i-1)+1]=v[1]
        data.vertices[3*(i-1)+2]=v[2]
        data.vertices[3*(i-1)+3]=v[3]
    end

    newVertices, newFaces=sim.getQHull(data.vertices) -- get convex hull
    newMeshh=sim.createMeshShape(0, 0, newVertices, newFaces)
	
--    sim.setObjectPosition(newMeshh, h, {0,0,0})
--	sim.setObjectOrientation(newMeshh, h, {0,0,0})
end
Cheers

Boris
Posts: 41
Joined: 14 Jun 2017, 12:40

Re: Wrong transformation after convex hull

Post by Boris »

Hi,

Thanks, this did indeed work.

Cheers,

Post Reply