draw a diagonal as rect

ppape's Avatar

ppape

13 Oct, 2017 12:17 PM

Hello,

having a rects width and height value, I would like to draw a rect that has the length and angle of the diagonal of that rect. To do this in trigonometry I would need a arctan function. But there is nothing like that in Nodebox 3 (I think). Is there another solution?

Thanks for help.

Philipp

  1. Support Staff 1 Posted by lucasnijs on 13 Oct, 2017 08:44 PM

    lucasnijs's Avatar

    Hello Philipp,
    attached is a sample file. You can use distance and angle to do what you want, no need for atan. Another way would be to use some pythagoras calc to calculate the diagonal.

    best,

    Lucas

  2. Support Staff 2 Posted by john on 13 Oct, 2017 09:37 PM

    john's Avatar

    Phillip,

    Lucas beat me to the punch, but since I made a demo network I'll share it anyway.

    As Lucas said, the angle and distance nodes give you want you want. Both of these nodes need a start and end point. In this case you want those points to be opposite corners of your rectangle. So how do you get those points?

    If you hook your rect to a point node you will get a list of the four corner positions of your rectangle. NodeBox rectangles start clockwise from the upper left, so you want a line from the fourth (last) corner to the second corner. For his solution Lucas first aligned the rect to the origin and started from the upper right so he could use 0,0 as his end point.

    Just for fun I created an animation that shows how this works. I added a caption and some flourishes like a little angle arc. You can also use this example to see how easy it is to animate things in NodeBox.

    Enjoy!

    John

  3. 3 Posted by ppape on 15 Oct, 2017 10:18 AM

    ppape's Avatar

    Thank you John and Lucas, that's of great help.

    Now I am thinking of a way to translate the rect so that it sits in the middle of the diagonal. But I didn't think to much about that yet. The big problem is solved.
    Thank you very much again.
    Philipp

  4. Support Staff 4 Posted by lucasnijs on 15 Oct, 2017 12:41 PM

    lucasnijs's Avatar

    You're welcome!
    Use the centroid node, attach the first rectangle to it, use this point to translate your diagonal rectangle to and hopla! (be sure your rectangle is aligned properly before you translate)

  5. Support Staff 5 Posted by john on 15 Oct, 2017 10:02 PM

    john's Avatar

    You are most welcome, Phillip. Thanks too, Lucas. It's fun to tag team with you.

    Here, just for fun, is another demo: a set of recursive rectangles. Each child rectangle is centered and rotated along the major diagonal of its parent. You can individually scale each child. Changes to the original rectangle produce dramatic results!

    Screenshot and network attached. Enjoy! And please consider sharing whatever you finally come up with in the Show Your Work forum.

    John

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

23 Mar, 2023 09:43 PM
23 Mar, 2023 09:24 AM
21 Mar, 2023 11:00 AM
21 Mar, 2023 09:32 AM
21 Mar, 2023 04:46 AM

 

12 Mar, 2023 03:02 AM
11 Mar, 2023 02:11 AM
10 Mar, 2023 06:47 AM
10 Mar, 2023 12:46 AM
02 Mar, 2023 08:49 PM
27 Feb, 2023 01:29 PM