draw a diagonal as rect

ppape's Avatar


13 Oct, 2017 12:17 PM


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.


  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.



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

    john's Avatar


    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.



  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.

  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.


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


? 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

13 Jul, 2024 06:05 AM
11 Jul, 2024 03:48 PM
28 Jun, 2024 01:51 PM
27 Jun, 2024 02:56 PM
27 Jun, 2024 01:57 PM


26 Jun, 2024 08:17 PM
26 Jun, 2024 11:35 AM
24 Jun, 2024 02:42 AM
24 Jun, 2024 12:46 AM
23 Jun, 2024 08:07 AM
08 Jun, 2024 09:05 AM