OffsetContour function

You can map z value to y value like y = - z, do the stuff with offset, then map the result back to XZ plane, where z = -y.

For example:

var points3d = [ // initial points from XZ plane
    new THREE.Vector3(0, 0, -1),
    new THREE.Vector3(1, 0, -1),
    new THREE.Vector3(1, 0, 0)
];
var points2d = points3d.map( p => {return new THREE.Vector2(p.x, -p.z);}); // to XY plane

// do the stuff with OffsetContour
// suppose, you've got points (of THREE.Vector2()) with offset in pointsOffset variable
var result3d = poinsOffset.map( p => {return new THREE.Vector3(p.x, 0, -p.y);}); // now put your offset points back on XZ plane

It’s just from the scratch, haven’t tested.

@prisoner849 that is right i did that but still some time that algorithm give me wrong offset and once i reverse the point it work fine so here my question how i determine that when i have to reverse the point or is there any way to make the points in the correct order.

Accpected output after reversing the shared points

image

You can use that method of ShapeUtils: https://threejs.org/docs/index.html#api/en/extras/ShapeUtils.isClockWise
If it returns true, then call .reverse() on the array of points.

1 Like

@prisoner849 thanks a lot for your help. I really appreciate your response and learning you provided to me.

1 Like

In this algo, one scenerio arise that. Sometime my shift value is so large and also in that case the point for which i am getting a large shift that is incorrect, so it give me that point at a large distance.

Means for an example my square contour, looks like an pentagon sort of.

How can we handle such situation.

@Alex Any chance to provide an editable working live code example, that demonstrates the issue?

1 Like