osresearch / plotter-vision

Hidden Wireframe removal demo in p5.js
GNU General Public License v2.0
89 stars 17 forks source link

Fix z-ordering #23

Closed brainsmoke closed 3 years ago

brainsmoke commented 3 years ago

Screen coordinates are used in the calculation of baryonic coordinates, but the calculation of the z-coordinate is done in a way that breaks the invariant of straight lines remaining straight.

This fix divides the z-coordinate by the same as the x and y coordinates are divided.

z' = (z-1)/z

This projects z = [1..+inf] onto z' = [0..1]

Reproducible problem:

scale([.1,50,10])
rotate([90,0,90])
cylinder(1,1,1,$fn=3);
translate([-4.01,0,0])
sphere(4);
brainsmoke commented 3 years ago

z-order

osresearch commented 3 years ago

Before: image

With this patch: image

I think this makes things worse? The before is definitely not perfect with some of the edges disappearing.

osresearch commented 3 years ago

Re-reverted in https://github.com/osresearch/plotter-vision/commit/5d775804893526816a479e70082aebb3007e97f3