Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotating a cylinder causes 3MF validation error #494

Closed
hannobraun opened this issue Apr 22, 2022 · 1 comment · Fixed by #1593
Closed

Rotating a cylinder causes 3MF validation error #494

hannobraun opened this issue Apr 22, 2022 · 1 comment · Fixed by #1593
Labels
topic: core Issues relating to core geometry, operations, algorithms topic: export Exporting to external file formats type: bug Something isn't working

Comments

@hannobraun
Copy link
Owner

Rotating cylinders is possible as of #493. However, it produces an invalid 3MF file.

Here's the code of a model that displays the issue:

use std::{collections::HashMap, f64::consts::FRAC_PI_4};

use fj::syntax::*;

#[no_mangle]
pub extern "C" fn model(_: &HashMap<String, String>) -> fj::Shape {
    let cylinder = fj::Circle::from_radius(0.5)
        .sweep(1.0)
        .rotate([1., 1., 1.], FRAC_PI_4)
        .translate([4., 1., 1.]);

    cylinder.into()
}

And here's the error:
Screenshot from 2022-04-22 13-41-31

I wasn't able to see any obvious issues, so it must be something subtle. Probably a triangulation edge case, or possible it's related to the use of triangle representation for the cylinder side walls (#97).

@hannobraun hannobraun added type: bug Something isn't working topic: core Issues relating to core geometry, operations, algorithms topic: export Exporting to external file formats labels Apr 22, 2022
@hannobraun
Copy link
Owner Author

I can still reproduce this, although the original code no longer compiles.

Here's the updated code:

use std::f64::consts::FRAC_PI_4;

use fj::{syntax::*, Angle};

#[fj::model]
pub fn model() -> fj::Shape {
    let cylinder = fj::Sketch::from_circle(fj::Circle::from_radius(0.5))
        .sweep([0., 0., 1.])
        .rotate([1., 1., 1.], Angle::from_rad(FRAC_PI_4))
        .translate([4., 1., 1.]);

    cylinder.into()
}

This trips our own validation code now:

thread 'main' panicked at 'Invalid approximation: Distinct points are too close (a: [3.5976310729378174, 0.7470603182991596, 1.1553086087630227], b: [3.5976310729378174, 0.7470603182991596, 1.1553086087630229], distance: 0.0000000000000002220446049250313)
source of `a`: Some(
    (
        Curve @ 0x55a996ea1820,
        [
            3.1415926535897936,
        ],
    ),
)
source of `b`: Some(
    (
        Curve @ 0x55a996ea1a30,
        [
            3.1415926535897936,
        ],
    ),
)
', /home/hanno/Projects/main/fornjot/crates/fj-kernel/src/algorithms/approx/face.rs:51:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I've done some additional digging. This is the curve where a originates:

Curve {
    path: Line(
        Line {
            origin: [
                0.0,
                0.0,
            ],
            direction: [
                1.0,
                0.0,
            ],
        },
    ),
    surface: Surface @ 0x557f15d2bee0,
    global_form: GlobalCurve @ 0x557f15d0ffa0,
}

And the curve where b originates:

Curve {
    path: Circle(
        Circle {
            center: [
                0.0,
                0.0,
            ],
            a: [
                0.5,
                0.0,
            ],
            b: [
                0.0,
                0.5,
            ],
        },
    ),
    surface: Surface @ 0x557f15d2c970,
    global_form: GlobalCurve @ 0x557f15d0ffb0,
}

They reference different GlobalCurves, so this is probably just an object duplication issue. If so, this might be an instance of #1162.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: core Issues relating to core geometry, operations, algorithms topic: export Exporting to external file formats type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant