[BUG?] Snell's law constraint allows to use 2 points from 1 line..
Forum rules
and Helpful information
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help
Also, be nice to others! Read the FreeCAD code of conduct!
Also, be nice to others! Read the FreeCAD code of conduct!
[BUG?] Snell's law constraint allows to use 2 points from 1 line..
... and that produces a confusing result - 2 lines fixed at 90 deg angle (right side of the screen shot).
https://peertube.social/videos/watch/3f ... f8ec0d8d20
The video also show the problem:
-
- Veteran
- Posts: 3106
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
Where is the refracting boundary? You are supposed to click light ray, light ray, boundary. If you are trying to use a ray as the material boundary of course it makes no sense.
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
One of the lines is the boundary. The function allows to select 2 points from one line. It should not allow to do it.
-
- Veteran
- Posts: 3106
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
It's only debatably a bug when you don't do what the documentation tells you to do. At least getting a nonsensical result warns you.
IMO, more insidious is if you ray-trace through a raindrop to see how rainbows work, you find the ray is not specularly reflected inside the drop, but instead Snell's law is erroneously applied, despite the fact that the medium in which the light is traveling has not changed. It's not so obvious unless you look carefully. I noticed because my rainbow came out at 38 degrees not 42.
However, it's a feature not a bug, because the documentation says:
"Both rays can be on the same side of the interface, satisfying the constraint equation. This is physical nonsense, unless the ratio n2/n1 is 1.0, in which case the constraint emulates a reflection."
It's not clear why physical nonsense was chosen over doing the right thing. Maybe there's some application other than ray-tracing that can use the constraint. Clearly you can work-around by setting n2/n1=1 in those cases.
IMO, more insidious is if you ray-trace through a raindrop to see how rainbows work, you find the ray is not specularly reflected inside the drop, but instead Snell's law is erroneously applied, despite the fact that the medium in which the light is traveling has not changed. It's not so obvious unless you look carefully. I noticed because my rainbow came out at 38 degrees not 42.
However, it's a feature not a bug, because the documentation says:
"Both rays can be on the same side of the interface, satisfying the constraint equation. This is physical nonsense, unless the ratio n2/n1 is 1.0, in which case the constraint emulates a reflection."
It's not clear why physical nonsense was chosen over doing the right thing. Maybe there's some application other than ray-tracing that can use the constraint. Clearly you can work-around by setting n2/n1=1 in those cases.
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
Do you think it's worth to put any effort in this function? I guess it is hardly ever used and it works properly if used properly. It may be enough to document the behaviour.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
Probably not, but I wanted to flag that there is something wrong. Sometimes it might be one-line fix for the author of the code.
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
Of course; and if it isn't working as documented, it is a bug. So I thought it might be easier to change the docs .
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
-
- Veteran
- Posts: 3106
- Joined: Thu Sep 24, 2020 10:31 pm
- Location: Hawaii
- Contact:
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
The doc says:
"Select the endpoint of one line, an endpoint of another line, and the interface edge"
I think it's already explicit that you aren't supposed to do what the OP did.
It also says
"You will need two lines that are to follow a beam of light, and a curve to act as an interface. The lines should be on different sides of the interface."
So you aren't supposed to do reflections, even though it works if you set n2/n1 as it explains later.
Perhaps:
"You will need two lines that are to follow a beam of light, and a curve to act as an interface. The lines should be on different sides of the interface. (If they are not, so that the light ray is specularly reflected from the interface, you must set n2/n1 =1.)"
might be better, as it gets this issue upfront. Being able to do reflections like this might actually be useful in entirely different contexts, so it shouldn't be relegated to a footnote.
https://wiki.freecadweb.org/Sketcher_ConstrainSnellsLaw
"Select the endpoint of one line, an endpoint of another line, and the interface edge"
I think it's already explicit that you aren't supposed to do what the OP did.
It also says
"You will need two lines that are to follow a beam of light, and a curve to act as an interface. The lines should be on different sides of the interface."
So you aren't supposed to do reflections, even though it works if you set n2/n1 as it explains later.
Perhaps:
"You will need two lines that are to follow a beam of light, and a curve to act as an interface. The lines should be on different sides of the interface. (If they are not, so that the light ray is specularly reflected from the interface, you must set n2/n1 =1.)"
might be better, as it gets this issue upfront. Being able to do reflections like this might actually be useful in entirely different contexts, so it shouldn't be relegated to a footnote.
https://wiki.freecadweb.org/Sketcher_ConstrainSnellsLaw
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
It is indeed all there. @PrzemoF: would things be clearer if this special case was mentioned earlier?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..
OK, I think I didn't explain the problem clearly enough. The function requires 3 lines to works properly. Yet it works if one uses only 2 lines. It's against the programming principle "fail early and fail loudly". But as mentioned earlier it's probably not worth to change it if it works properly when the user knows how to use it.