sgenoud / replicad

The library to build browser based 3D models with code.
https://replicad.xyz
MIT License
323 stars 38 forks source link

extrusion of sketches goes in the wrong direction #89

Closed tve closed 11 months ago

tve commented 11 months ago

In the following example I'm extruding a sketch along the Y axis but a positive extrusion value results in extruding towards -Y. A subsequent translateY of the object has the direction of the Y axis correct. Example:

export default function main(p) {
  const tri1 = replicad.draw().vLine(10).lineTo([10,0]).close().sketchOnPlane("XZ").extrude(10)
  const tri2 = replicad.draw().vLine(10).lineTo([10,0]).close().sketchOnPlane("XZ").extrude(5)
  return [
    { shape: tri1, name: "tri1", color: "blue" },
    { shape: tri2.translateY(20), name: "tri1", color: "blue" },
  ]
}

image

sgenoud commented 11 months ago

This is due to the (mathematical definition of the XZ plane). If you do the cross product of X (1, 0, 0) and Z (0, 0, 1) you obtain -Y (0, -1, 0). When sketching in a plane, you will, by default extrude in the direction of the normal of the plane, -Y in this case.

That said, I completely understand the confusion, and I am not sure if that is the best choice (i.e. to be mathematically consistent instead of intuitive). There might be some edge case that pop when we start ignoring mathematical consistency.

The ZX plane is the one you where expected to get...

tve commented 11 months ago

Ah, right hand rule... I forgot... I'll get used to using ZX instead of XZ. I fear that if you make it "intuitive" via some special rule things will either be wrong or really confusing when someone uses a pivoted plane... E.g. what if I take XZ and pivot it 120 degrees around the Z axis, now what's + vs. -?