A diagram have an origin and a bounding box.
You can see this using
Diagram.debug
Points
// the + symbol shows the origin
// the gray lines shows the bounding box
// the red lines shows the path of the object
// the number shows the index of the point in the object
let pentagon = regular_polygon(5,10);
draw(pentagon.debug());
Diagram.debug (
show_index
:
boolean = true )
:
Diagram
// the + symbol shows the origin
// the gray lines shows the bounding box
// the red lines shows the path of the object
// the number shows the index of the point in the object
let pentagon = regular_polygon(5,10);
draw(pentagon.debug());
You can access the special points of the bounding box using
Diagram.get_anchor
// anchors can be :
// 'top-left', 'top-center', 'top-right',
// 'center-left', 'center-center', 'center-right',
// 'bottom-left', 'bottom-center', 'bottom-right',
let pentagon = regular_polygon(5,10);
let anchor_top = pentagon.get_anchor('top-center');
let anchor_bottom = pentagon.get_anchor('bottom-center');
let ctop = circle(0.5).fill('blue').position(anchor_top);
let cbot = circle(0.5).fill('blue').position(anchor_bottom);
draw(pentagon, ctop, cbot);
Diagram.get_anchor (
anchor
:
string )
:
Diagram
// anchors can be :
// 'top-left', 'top-center', 'top-right',
// 'center-left', 'center-center', 'center-right',
// 'bottom-left', 'bottom-center', 'bottom-right',
let pentagon = regular_polygon(5,10);
let anchor_top = pentagon.get_anchor('top-center');
let anchor_bottom = pentagon.get_anchor('bottom-center');
let ctop = circle(0.5).fill('blue').position(anchor_top);
let cbot = circle(0.5).fill('blue').position(anchor_bottom);
draw(pentagon, ctop, cbot);
You can get the bounding box directly using
Diagram.bounding_box
let pentagon = regular_polygon(5,10);
let bbox = pentagon.bounding_box(); // bbox = [v2_bottomleft, v2_topright]
let p1 = circle(0.5).position(bbox[0]).fill('red');
let p2 = circle(0.5).position(bbox[1]).fill('blue');
draw(pentagon, p1, p2);
Diagram.bounding_box (
)
:
[Vector2, Vector2]
let pentagon = regular_polygon(5,10);
let bbox = pentagon.bounding_box(); // bbox = [v2_bottomleft, v2_topright]
let p1 = circle(0.5).position(bbox[0]).fill('red');
let p2 = circle(0.5).position(bbox[1]).fill('blue');
draw(pentagon, p1, p2);
You can move the origin of the diagram using
Diagram.move_origin
// anchors can be :
// 'top-left', 'top-center', 'top-right',
// 'center-left', 'center-center', 'center-right',
// 'bottom-left', 'bottom-center', 'bottom-right',
let sq_red = square(10).fill('red' ).move_origin('bottom-left').position(V2(0,0));
let sq_blue = square(10).fill('blue').move_origin(V2(5,5) ).position(V2(0,0));
// both of the squares are positioned at the same location (0,0)
// but they have different origins
draw(sq_red, sq_blue);
Diagram.move_origin (
pos
:
Vector2 | string )
:
Diagram
// anchors can be :
// 'top-left', 'top-center', 'top-right',
// 'center-left', 'center-center', 'center-right',
// 'bottom-left', 'bottom-center', 'bottom-right',
let sq_red = square(10).fill('red' ).move_origin('bottom-left').position(V2(0,0));
let sq_blue = square(10).fill('blue').move_origin(V2(5,5) ).position(V2(0,0));
// both of the squares are positioned at the same location (0,0)
// but they have different origins
draw(sq_red, sq_blue);
You can retrieve origin of the diagram using
Diagram.origin
property
let sq_red = square(10).fill('blue' ).move_origin('bottom-left').position(V2(2,2));
let p = sq_red.origin;
let sq_blue = square(5).fill('white').position(p);
draw(sq_red, sq_blue);
let sq_red = square(10).fill('blue' ).move_origin('bottom-left').position(V2(2,2));
let p = sq_red.origin;
let sq_blue = square(5).fill('white').position(p);
draw(sq_red, sq_blue);
// Path can be described parametrically in the form of (x(t), y(t))
// Path starts at t=0 and ends at t=1
// if segment_index is not defined, t=0 is the start of the path and t=1 is the end of the path
// *you can see where path starts and ends using Diagram.debug()
let pentagon = regular_polygon(5,10);
let p0 = pentagon.parametric_point(0);
let p1 = pentagon.parametric_point(0.25);
let p2 = pentagon.parametric_point(0.5);
let p3 = pentagon.parametric_point(0.75);
let c0 = circle(0.5).fill('blue').position(p0);
let c1 = circle(0.5).fill('blue').position(p1);
let c2 = circle(0.5).fill('blue').position(p2);
let c3 = circle(0.5).fill('blue').position(p3);
draw(pentagon, c0, c1, c2, c3);
Diagram.parametric_point (
t
:
number , segment_index?
:
number )
:
Vector2
// Path can be described parametrically in the form of (x(t), y(t))
// Path starts at t=0 and ends at t=1
// if segment_index is not defined, t=0 is the start of the path and t=1 is the end of the path
// *you can see where path starts and ends using Diagram.debug()
let pentagon = regular_polygon(5,10);
let p0 = pentagon.parametric_point(0);
let p1 = pentagon.parametric_point(0.25);
let p2 = pentagon.parametric_point(0.5);
let p3 = pentagon.parametric_point(0.75);
let c0 = circle(0.5).fill('blue').position(p0);
let c1 = circle(0.5).fill('blue').position(p1);
let c2 = circle(0.5).fill('blue').position(p2);
let c3 = circle(0.5).fill('blue').position(p3);
draw(pentagon, c0, c1, c2, c3);
// You can also give it a `segment_index`
// Let's say you want to get the point between the 3rd and 4th point i.e. (3rd segment)
// *you can see the index of each point using `Diagram.debug()`
let pentagon = regular_polygon(5,10);
let p = pentagon.parametric_point(0.5, 3);
let c = circle(0.5).fill('blue').position(p);
draw(pentagon, c);
// You can also give it a `segment_index`
// Let's say you want to get the point between the 3rd and 4th point i.e. (3rd segment)
// *you can see the index of each point using `Diagram.debug()`
let pentagon = regular_polygon(5,10);
let p = pentagon.parametric_point(0.5, 3);
let c = circle(0.5).fill('blue').position(p);
draw(pentagon, c);
let pentagon = regular_polygon(5,10);
let p2 = pentagon.add_points([V2(0,0), V2(-1,2), V2(9,5)]);
draw(p2);
Diagram.add_points (
points
:
Vector2[] )
:
Diagram
let pentagon = regular_polygon(5,10);
let p2 = pentagon.add_points([V2(0,0), V2(-1,2), V2(9,5)]);
draw(p2);