Function: Vector2

UDF library of functions to use with 2 dimensional vectors.
Release Notes: structured the function list better, added a few more functions and updated label for the tests to be more readable.
Release Notes: added functions: assign, rescale, perp, angle, project, reflect, array center.
Release Notes: changed: assign function to from.
changed: move_to function to lerp.
added: atan2, min, max, scale, angle, clamp.
Release Notes: moved some functions location: _normalize, _rescale
added function: _get_xy to return x,y elements in a tuple form.
improved casting within library calls.
Release Notes: Added array methods: size, sum, push, pop, unshift, shift.
Release Notes: added function to get the area of a triangle with 3 vector coordinates.
Release Notes: added functions:line_new, line_get_a, line_get_b, line_intersection, draw_line
Release Notes: added functions: rotate_around, array_rotate_points, line_new, line_get_a, line_get_b, line_intersect, draw_line, draw_triangle, draw_rect.
note: draw_rect has the option to rotate its position around its origin vector.
Release Notes: added function: array_scale_points, allows to scale a array of vectors based on a perspective origin.
Release Notes: removed vector2_(pi, phi, e, todegrees, toradians) in favour of their new builtin counter parts.
math_fractional, vector2_fractional, vector2_floor, vector2_sin, vector2_random, vector2_herp, vector2_noise

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?