What does the new "ray length" option do?

(This is a template, feel free to delete it.)

What's problem you are encountering? I have never seen this block before. I found out about it while reading https://github.com/jmoenig/Snap/releases/tag/v6.4.0.

What have you tried that didn't work? I haven't tried anything yet because I don't know what it does

Post a project example, link, or screenshot:
untitled script pic (14)

Also what do these blocks do, and why are they hidden in the block palette?
untitled script pic (15)

The max and min blocks return the biggest or smallest values between two numbers respectively. No idea what atan2 does.


Still doesn't explain what atan2 does, but at least it explains why they're hidden

So, we've forever had DISTANCE TO, which measures from the rotation center of one sprite to the rotation center of the other, paying no attention to what direction they're facing.

RAY LENGTH measures the distance from the rotation center of the current (asking) sprite to the nearest edge of the other sprite, going in the direction in which the first sprite is facing.

Okay, about ATAN2: If you've studied trig, skip to the next paragraph. Think about the slope of a line. For example, a tilted roof, which they use in building houses so that rainwater doesn't collect on the roof and end up leaking into the house. A roof can be really pointy, or it can be nearly flat, or anything in between. Slope is a measure of how pointy it is. As you walk from the bottom of the roof to the top, the slope is the ratio of how much higher off the ground you are (Δy, the change in y) divided by how much distance parallel to ther ground you walked, from the outer edge of the house to the middle (supposing that's where it peaks), Δx. Another way to think about the slope of the roof is to ask what angle it makes with the horizontal. So, for a flat roof it's 0°; if you imagine a vertical roof, the angle would be 90°. There are two functions, inverses of each other, that relate the two measures, slope and angle:
slope = tan(angle); angle = arctan(slope). "Tan" is short for "tangent"; "arctan" is short for "arctangent." "Arctan" is how mathematicians write it; computer programmers, who are notoriously lazy, spell it "atan." Tan and atan are two of the options in the huge menu of functions in the SQRT OF block.

Now think about that hypothetical vertical roof. Its slope, Δy/Δx, is infinite, because no matter how much you walk vertically, you stay in the same place horizontally. But it has a perfectly well-defined, finite angle: 90°.

Okay, now, you're doing some computer graphics. You have two points, and you want to get from one to the other. What you know is the X POSITION and Y POSITION of each of the two points, and you want to know the angle. (Why do you want that? Just trust me, that's often what people want.) So you write

Right? Make sure you believe that before we go on.

This formula works great, unless the two points happen to be one directly above the other. In that case, the difference between the X positions is 0, so the quotient is infinite. So you don't write that. Instead you write

which means, divide the first input by the second input and take the arctangent, unless the second input is zero, in which case report 90 if the first input is positive or -90 if the first input is negative. That's atan2.

All of the above is the story out in the real world, where angles are measured counterclockwise from East, and where negative numbers are frowned upon. The details are a little different in Snap!. Because we measure angles from vertical rather than from horizontal, it turns out that our slopes are Δx/Δy instead of Δy/Δx. So our atan2 takes the horizontal distance in the first input and the vertical distance in the second input. And also, it turns out that our ATAN function has its domain extended to include ∞ and -∞, returning 90 and -90 respectively. So our users don't have to use atan2 at all. But if you're trying to translate code from some other language, it's there if you need it.

About hiding these functions behind RELABEL: It's sort of a compromise. Users want every function that you'd find in any other programming language, and they're right, so we want to provide them. But on the other hand, we're about teaching computer science, not math, so the actual writing of those functions, especially max and min, are great exercises kids shouldn't lose. So this is an experiment in having our cake and eating it too.

And also if two vectors facing the opposite direction are not the same.

Are you saying that the "lasers", used in my recent project, haven't been needed in the first place? Because all they do is measuring the distance in the direction they are individually facing, which is, if I understand correctly, what you have just said this new block does?

Yeah, I think that's right. Although it didn't exist until 6.5.0 which just came out a few days ago, so don't feel bad about it!

Should I feel -- because the project that made me proud of learning to use the Map block for media computation (the one with fuzzy rgb criteria used for making parts of a costume transparent, that you liked it) becoming, after the CUT block appeared, obsolete to a certain degree; and, now, also 'lasers measurement', after the 'ray length' option is added to the 'TO' block, is obsolete, too -- cheated or flattered?

Thank you very much!

Oh, flattered, definitely. Every new feature in a language is going to make some things easier; that's what features are for. So if you're going to be annoyed about that you're asking for the language never to change.

Hyperblocks made MAP obsolete for many purposes, and I have the same ambivalence about that as you do about this. But it makes Snap! a better language.

Judging by the time it took me, firstly, to understand; secondly, find interesting use cases for my projects; and, thirdly, to appreciate MAP (and KEEP and COMBINE), it will probably take me additional two and a half years to do the same with hyperblocks.

Can you give me an example of hyperblocks making MAP obsolete and why is that making Snap! better, to maybe speed up the process?

Jens likes hyperblocks for speed. I do too, but also, beginners are always saying
Untitled script pic
by mistake when they mean

and now it's not a mistake any more.

I've been reading R lately, and that is exactly the kind of mistake I need to start making

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.