## [BUG?] Snell's law constraint allows to use 2 points from 1 line..

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules

PrzemoF
Posts: 3166
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

### [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).
Zrzut ekranu z 2021-04-07 19-16-45.png (150.15 KiB) Viewed 226 times
The video also show the problem: https://peertube.social/videos/watch/3f ... f8ec0d8d20
edwilliams16
Posts: 323
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.
PrzemoF
Posts: 3166
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

### 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.
edwilliams16
Posts: 323
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.
chrisb
Posts: 34314
Joined: Tue Mar 17, 2015 9:14 am

### Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..

PrzemoF wrote:
Wed Apr 07, 2021 7:53 pm
It should not allow to do it.
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.
PrzemoF
Posts: 3166
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

### Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..

chrisb wrote:
Wed Apr 07, 2021 9:30 pm
PrzemoF wrote:
Wed Apr 07, 2021 7:53 pm
It should not allow to do it.
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.
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.
chrisb
Posts: 34314
Joined: Tue Mar 17, 2015 9:14 am

### Re: [BUG?] Snell's law constraint allows to use 2 points from 1 line..

PrzemoF wrote:
Wed Apr 07, 2021 9:39 pm
Sometimes it might be one-line fix for the author of the code.
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.
edwilliams16
Posts: 323
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.

chrisb
Posts: 34314
Joined: Tue Mar 17, 2015 9:14 am

### 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.
PrzemoF
Posts: 3166
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

### 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.