draw a diagonal as rect
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.
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
Support Staff 1 Posted by lucasnijs on 13 Oct, 2017 08:44 PM
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.
Support Staff 2 Posted by john on 13 Oct, 2017 09:37 PM
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 Posted by ppape on 15 Oct, 2017 10:18 AM
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.
Support Staff 4 Posted by lucasnijs on 15 Oct, 2017 12:41 PM
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)
Support Staff 5 Posted by john on 15 Oct, 2017 10:02 PM
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.