RoboCompass has 10 drawing commands and 12 helper commands. Drawing commands can be assigned labels and referenced in other commands.
In effect, these commands can be combined in creative ways to produce all sorts of Geometrical constructions.
Command |
Purpose and Examples |
---|---|
point(x, y) | Example:- point(3, 4) or A=point(3, 4) where A is the label. |
line(x1, y1, x2, y2) | Example:- line(0,0,-2,5) or C=line(A, B) where A, B are point labels. Length can be optionally given as line(A, B, 3) where 3 is length of segment. |
arc(originPoint, radius, angleFrom, upto) | Example:- arc(point(2, 2), 3, 40, 20)Uses point(2, 2) as origin, 3 as radius and starts the arc from 40 degrees adding another 20 degree in an anticlockwise direction. A negative value for "upto" parameter will move clockwise. To copy a line, give the first parameter as line or two points as shown here arc(point1, point2, originPoint, angleFrom, upto) |
perp(line, passThroughPoint, length=10) | Example:- A=perp(line(1, 2, 3, 4), point(1, 2)) draws a perpendicular line to a given line(1, 2, 3, 4) passing through point(1, 2). The last optional parameter of perp command is the length of the perpendicular line which defaults to 10 |
parallel(line, passThroughPoint, length=10) | Example:- parallel(line(1, 2, 3, 4), point(1, 2)) |
angle(point1, point2, degrees) | Example:- angle(A, B, 45, 1) The two points A and B defines the base line.The ratio is an optional parameter which controls the position of the protractor. A value of 0 places it at A, 1 at B and 0.5 in the middle. |
polygon(comma separated points) | Example:- polygon(A, B, C) draws a triangle where A, B, C are points |
findangle(2 lines or a polygon) | Example:- findangle(A, B) finds the angle between two lines A, B or a polygon findangle(C) (C is the label of polygon, in this case the method returns the first angle) |
fill(A, B) | Fills the interior of shapes A,B.The shapes can be an arc, polygon or another fill. The command accepts any number of shapes. fill(A), fill(arc(0, 0, 3, 0, 360), D, polygon(2, 3, 4, 6, 1, 0)) |
trace(comma separated points) | Traces the curve passing through the given points. trace(point(0, 0), point(1, sin(30)), point(1, sin(60)), point(1, sin(120)), B) |
part(shape to extract from, 2 points on shape, optional part Index) | Example:- part(a,D,E,2) or A=part(a,intersect(a,b,1), point(2,3)) where A is the label of the shape to take part from. The shape 'a' in the example refers to a polygon or line or arc. The 2 points given after the shape needs to be on the shape (ie if it is arc, then the point must be on arc's perimeter, the same is true for polygon, the points must be on one of the lines of the polygon. The part command extracts 2 shapes, so we can specify an optional partIndex (either 1 or 2) and the point to get the desired part as shown here. part(a,intersect(a,b,1), point(2,3), 2) The last value 2 extracts the second part. You can only give either 1 or 2 as part index. The returned part which is stored in 'A' can then be used to build further complex shape used for tessllations. For example polygon(2,4,6,7,A,10,12) In this example a new polygon will be created by using points 2,4,6,7 and points from the 'A' part commands that follow them |
fade(labels of shape, fade factor) | Example:- fade(a,D,E, 0.4) The fade factor(last) value which must be between 0 to 1 which controls how much the objects should fade in or out |
pointtype('cross') | Example:- pointtype('cross') Changes the point style from 'sphere' to 'cross'. Any point command after this pointtype command will render a cross, if we want to go back to 'sphere' just put another pointtype() command without any values |
dash(x1, y1, x2, y2, dashLength, dashGapLength) | Example:- dash(3,4,7,8,0.5,0.6) Draws a dashed line, the 5th argument controls the dash length and 0.6 (the last value) controls the gap. Using these 2 values we can draw dotted lines as well. Like other robocompass commands, instead of giving 4 values directly, we can either give a 2 points or any expression that resolves to 4 coordinates similar to dash(A, C, 1.2, 0.5) where A, C are point labels |
stroke(labels of shape, thickness) | Example:- stroke(a,D,E, 3) Changes the thickness of the shapes refered by the labels. The thickness must be greater than 0 and there is no upper limit |
reverse(labels of shape) | Example:- reverse(a) Reverses the coordinates of the shape. This will be useful in building complex tessellations. Generally used inside polygon(reverse(L), 3,7,8,1) , The L here could be a part or a line or any shape. You can also give more than one shape as argument |
plot("expression") | Example:- plot("sin(x)") or A=plot("tan(x)",2,10) where A is the label. The min and max values after expression are optional By default the plot covers the entire graphsheet area. As in other functions, variables can be defined elsewhere and refereed inside the expression. All geometric transformations like rotate,translate,dilate and clipping operations (and, or) can be performed on the resultant plot. Implicit equations such as "x^2+y^2=r^2 are not supported. However you can give equations such as "y=2*x" or "x=2y". |
para("expression1","expression2") | Example:- para("2*sin(t)","3*cos*(t)") or A=para("2*sin(t)","3*cos*(t)",0,6.29,0.1) where A is the label. The expressions must have "t" as parameter. The min and max and step values after expressions are optional. pos command can be used to get a point at a particular point in graph like pos(p,0.2) where p is p=plot("some exp") or p=para("some exp") |
General rule | Whenever a point is expected in an expression, use either point(2, 3), its label or a helper command which calculates and returns a point. Similarly wherever a line is expected give the label of a line or the label of two points. For example arc(A, B, point(2, 1), 50, 40) uses the distance from A to B and draws the arc from point(2, 1).
|
point(x,y)
A=point(3,4)line(x1,y1,x2,y2)
line(0,0,-2,5)arc(originPoint,radius,angleFrom,upto)
arc(point1,point2,originPoint,angleFrom,upto)
perp(line,passThroughPoint,length=10)
A=perp(line(1,2,3,4),point(1,2))
perp(A,B)
parallel(line,passThroughPoint,length=10)
parallel(line(1,2,3,4),point(1,2))
parallel(A,B)angle(point1,point2,degrees)
angle(point(2,0),point(6,0),45)
angle(A,B,90,1)polygon(comma separated points)
polygon(point(2,2),point(4,2),point(3,5))
polygon(A,B,C)findangle(2 lines or a polygon)
findangle(A,B)fill(A,B,fillType=0,output=1)
fill(A)trace(comma separated points)
trace(point(0,0),point(1,sin(30)),point(1,sin(60)),point(1,sin(120)),B)plot(math expression,min?,max?)
plot("sin(x)")para(expression1,expression2,min?,max?)
para("2*sin(t)","2*cos(t)",0,6.29,0.1)pointtype('cross')
pointtype('cross')
pointtype()dash(x1,y1,x2,y2)
dash(0,0,-2,5)fade(labels of shape, fade-ratio)
fade(a,b,c,d,0.5)
marker(label of part)
marker(part1)
part(label of shape, 2 points on shape, partIndex)
side1=part(a,intersect(a,b,1),intersect(a,c,2))
side2=part(d,A,B,1)reverse(label of shape)
polygon(reverse(part1),A,B)
polygon(reverse(a),A)stroke(labels of shape, thickness)
stroke(a,b,c,d,3)
Command |
Purpose and Examples |
---|---|
dist(point1, point2) | Calculates the distance between two points. Give a dist(C)if C is a line (i.e. segment) |
X(point) | Gives the X coordinate of a point A. A= X(point(2,1)) |
Y(point) | Gives the Y coordinate of a point A. B= Y(point(1,2)) |
pos(polygon or line or arc, index) | Returns the point at a given index. If a polygon A has 4 points, pos(A, 3) returns the third point, Similarly if a line's label is B a index of 2 returns the end point. Example:- pos(B, 2) |
intersect(object1, object2, index=1) | Intersects any two objects (except points).Example G=point(intersect(D, E)) By default returns the first intersecting point, for second and third intersecting point, give 2 or 3 respectively. For example this intersect(D, E, 2) gives the second intersecting point. |
reflect(object, line) | Reflects the object by a given line. Example:- reflect(D, A) where D is the label of point to reflect and A is the reflecting line |
rotate(object, angle, withrespectTo=point(0, 0)) | Rotates the object by a given degree. By default, the rotation is with respect to origin (0, 0), which can be optionally overridden by giving the parameter withrespectPoint. |
translate(object, x, y, withrespectTo=point(0, 0)) | Translates the object by given x, y with respect to origin or by given withRespectTo parameter. translate(arc(2, 3, 3, 0, 180), 2, 3, point(2, 1)) or translate(G, 2, 4) |
dilate(object, scaleFactor, withRespectTo=point(0, 0)) | Dilates the object by a given scaleFactor parameter.dilate(point(3, 1), 2) |
project(point1, line) | Projects the input point on the line and returns the projected point. Example:-project(A, line(0, 0, 1, 0)) projects the point A on the given line. |
interpolate(point1, point2, ratio) | Example:- interpolate(A, B, 0.5) A ratio of 0.5 returns the midpoint of A, B |
hide(comma separated labels) | Example:- hide(A, B, C, D) hides objects A, B, C, D. To show again use show(A, B, C, D) |
group(comma separated objects) | Transformations can be applied on multiple objects simultaneously by creating a group. For example to rotate both a arc 'A' and a polygon 'B' together, use C=group(A, B) and then D=rotate(C, 120) where C is the label of the group. Groups can also be nested. |
Boolean operations - and, or, diff | A variety of shapes can be created by applying Boolean operations on simple shapes. These shapes can be tessellated by transformation commands. For example and(A, B, C) creates a polygonal region common (intersection) to A, B, C where A, B, C can be an arc or a polygon. Similarly, or(A, E, polygon(0, 0, 2, 3, 4, 1)) and diff(A, B) create union and difference of the given regions respectively. Regions with interior holes are not supported (resulting from an xor operation), but the same result can be created by combining multiple polygons using the group command. |
text("String") text("String", x-coordinate, y-coordinate) | Example: text("Hello World!") Example: text("Hello World!", 3, 3) |
Note: |
dist(point1, point2)
dist(point(2,1),point(1,2))X(point)
A=X(point(2,1))
X(A)Y(point)
B=Y(point(1,2))
Y(A)pos(polygon or line or arc,index)
pos(B,2)intersect(object1,object2,index=1)
G=point(intersect(D,E))
intersect(D,E,2)reflect(object,line)
reflect(point(2,2),line(4,0,4,4))
reflect(D,A)rotate(object,angle,withrespectTo=point(0,0))
rotate(point(2,2),90,point(0,0))
rotate(D,30,A)translate(object,x,y,withrespectTo=point(0,0))
translate(arc(2,3,3,0,180),2,3,point(2,1))
translate(G,2,4)dilate(object,scaleFactor,withRespectTo=point(0,0))
dilate(point(3,1),2)
dilate(M,0.5,point(8,0))project(point1,line)
project(point(2,2),line(0,0,1,0))
project(A,line(0,0,1,0))interpolate(point1,point2,ratio)
interpolate(point(0,0),point(10,0),0.3)
interpolate(A,B,0.5)hide(comma separated labels)
hide(A,B,C,D)
show(A,B,C,D)group(comma separated objects)
C=group(A,B)
m=group(a,b,c,d)and(comma separated objects)
and(A,B,C)or(comma separated objects)
or(A,E,polygon(0,0,2,3,4,1))diff(comma separated objects)
diff(A,B)text("String")
text("String",x-coordinate,y-coordinate)
text("Hello World!")For unrestricted access download Robocompasspro
Robocompass Desktop Version