1 # Created by Octave 3.6.2, Sun Jun 10 09:53:43 2012 UTC <root@brouzouf>
13 # name: <cell-element>
17 -- Function File: ALPHA = angle2Points (P1, P2)
18 Compute horizontal angle between 2 points
20 P1 and P2 are either [1x2] arrays, or [Nx2] arrays, in this case
21 ALPHA is a [Nx1] array. The angle computed is the horizontal angle
24 Result is always given in radians, between 0 and 2*pi.
26 See also: points2d, angles2d, angle3points, normalizeAngle,
33 # name: <cell-element>
37 Compute horizontal angle between 2 points
42 # name: <cell-element>
49 # name: <cell-element>
53 -- Function File: ALPHA = angle3Points (P1, P2, P3)
54 Computes the angle between the points P1, P2 and P3.
56 P1, P2 and P3 are either [1x2] arrays, or [Nx2] arrays, in this
57 case ALPHA is a [Nx1] array. The angle computed is the directed
58 angle between line (P2P1) and line (P2P3).
60 Result is always given in radians, between 0 and 2*pi.
62 See also: points2d, angles2d, angle2points
68 # name: <cell-element>
72 Computes the angle between the points P1, P2 and P3.
76 # name: <cell-element>
83 # name: <cell-element>
87 -- Function File: DIF = angleAbsDiff (ANGLE1, ANGLE2)
88 Computes the absolute angular difference between two angles in
89 radians. The result is comprised between 0 and pi.
91 A = angleAbsDiff(pi/2, pi/3)
93 0.5236 % equal to pi/6
95 See also: angles2d, angleDiff
101 # name: <cell-element>
105 Computes the absolute angular difference between two angles in radians.
109 # name: <cell-element>
116 # name: <cell-element>
120 -- Function File: DIF = angleDiff (ANGLE1, ANGLE2)
121 Difference between two angles
123 Computes the signed angular difference between two angles in
124 radians. The result is comprised between -PI and +PI.
126 Example A = angleDiff(-pi/4, pi/4) A = 1.5708 %
127 equal to pi/2 A = angleDiff(pi/4, -pi/4) A =
128 -1.5708 % equal to -pi/2
130 See also: angles2d, angleAbsDiff
136 # name: <cell-element>
140 Difference between two angles
145 # name: <cell-element>
152 # name: <cell-element>
156 -- Function File: varargout = angleSort (PTS, varargin)
157 Sort points in the plane according to their angle to origin
159 PTS2 = angleSort(PTS); Computes angle of points with origin, and
160 sort points with increasing angles in Counter-Clockwise
163 PTS2 = angleSort(PTS, PTS0); Computes angles between each point
164 of PTS and PT0, which can be different from origin.
166 PTS2 = angleSort(..., THETA0); Specifies the starting angle for
169 [PTS2, I] = angleSort(...); Also returns in I the indices of
170 PTS, such that PTS2 = PTS(I, :);
172 See also: points2d, angles2d, angle2points, normalizeAngle
178 # name: <cell-element>
182 Sort points in the plane according to their angle to origin
187 # name: <cell-element>
194 # name: <cell-element>
198 -- Function File: angles2d ()
199 Description of functions for manipulating angles
201 Angles are normalized in an interval of width 2*PI. Most geom2d
202 functions return results in the [0 2*pi] interval, but it can be
203 convenient to consider the [-pi pi] interval as well. See the
204 normalizeAngle function to switch between conventions.
206 Angles are usually oriented. The default orientation is the CCW
207 (Counter-Clockwise) orientation.
209 See also: angle2Points, angle3Points, angleAbsDiff,
210 normalizeAngle, vectorAngle, angleDiff, angleSort, lineAngle,
211 edgeAngle, deg2rad, rad2deg
217 # name: <cell-element>
221 Description of functions for manipulating angles
226 # name: <cell-element>
233 # name: <cell-element>
237 -- Function File: [TANGENT,INNER] = beltproblem (C, R)
238 Finds the four lines tangent to two circles with given centers and
241 The function solves the belt problem in 2D for circles with center
246 2-by-2 matrix containig coordinates of the centers of the
247 circles; one row per circle.
250 2-by-1 vector with the radii of the circles.
254 4-by-4 matrix with the points of tangency. Each row describes
258 4-by-2 vector with the point of intersection of the inner
259 tangents (crossed belts) with the segment that joins the
260 centers of the two circles. If the i-th edge is not an inner
261 tangent then `inner(i,:)=[NaN,NaN]'.
267 [T inner] = beltproblem(c,r)
269 -0.68516 0.72839 1.34258 2.63581
270 0.98516 0.17161 0.50742 2.91419
271 0.98675 -0.16225 1.49338 2.91888
272 -0.88675 0.46225 0.55663 3.23112
286 # name: <cell-element>
290 Finds the four lines tangent to two circles with given centers and
295 # name: <cell-element>
302 # name: <cell-element>
306 -- Function File: RAY = bisector (LINE1, LINE2)
307 -- Function File: RAY = bisector (P1, P2, P3)
308 Return the bisector of two lines, or 3 points.
310 Creates the bisector of the two lines, given as [x0 y0 dx dy].
312 create the bisector of lines (P2 P1) and (P2 P3).
314 The result has the form [x0 y0 dx dy], with [x0 y0] being the
315 origin point ans [dx dy] being the direction vector, normalized
318 See also: lines2d, rays2d
324 # name: <cell-element>
328 Return the bisector of two lines, or 3 points.
332 # name: <cell-element>
339 # name: <cell-element>
343 -- Function File: boxes2d ()
344 Description of functions operating on bounding boxes.
346 A box is represented as a set of limits in each direction:
347 BOX = [XMIN XMAX YMIN YMAX].
348 Boxes are used as result of computation for bounding boxes, and to
351 See also: clipPoints, clipLine, clipEdge, clipRay, mergeBoxes,
352 intersectBoxes, randomPointInBox, drawBox
358 # name: <cell-element>
362 Description of functions operating on bounding boxes.
366 # name: <cell-element>
373 # name: <cell-element>
377 -- Function File: LINE = cartesianLine (A, B,C)
378 Create a straight line from cartesian equation coefficients.
380 Create a line verifying the Cartesian equation: A*x + B*x + C =
383 See also: lines2d, createLine
389 # name: <cell-element>
393 Create a straight line from cartesian equation coefficients.
397 # name: <cell-element>
404 # name: <cell-element>
408 -- Function File: PP = cbezier2poly (POINTS)
409 -- Command: Function File [X Y] = cbezier2poly (POINTS,T)
410 Returns the polynomial representation of the cubic Bezier defined
411 by the control points POINTS.
413 With only one input argument, calculates the polynomial PP of the
414 cubic Bezier curve defined by the 4 control points stored in
415 POINTS. The first point is the inital point of the curve. The
416 segment joining the first point with the second point (first
417 center) defines the tangent of the curve at the initial point.
418 The segment that joints the third point (second center) with the
419 fourth defines the tanget at the end-point of the curve, which is
420 defined in the fourth point. POINTS is either a 4-by-2 array
421 (vertical concatenation of point coordinates), or a 1-by-8 array
422 (horizotnal concatenation of point coordinates). PP is a 2-by-3
423 array, 1st row is the polynomial for the x-coordinate and the 2nd
424 row for the y-coordinate. Each row can be evaluated with
425 `polyval'. The polynomial PP(t) is defined for t in [0,1].
427 When called with a second input argument T, it returns the
428 coordinates X and Y corresponding to the polynomial evaluated at T
431 See also: drawBezierCurve, polyval
437 # name: <cell-element>
441 Returns the polynomial representation of the cubic Bezier defined by
446 # name: <cell-element>
453 # name: <cell-element>
457 -- Function File: C = centroid (POINTS)
458 -- Function File: C = centroid (PX, PY)
459 -- Function File: C = centroid (..., MASS)
460 Compute centroid (center of mass) of a set of points.
462 Computes the ND-dimensional centroid of a set of points. POINTS
463 is an array with as many rows as the number of points, and as
464 many columns as the number of dimensions. PX and PY are two
465 column vectors containing coordinates of the 2-dimensional
466 points. The result C is a row vector with ND columns.
468 If MASS is given, computes center of mass of POINTS, weighted by
469 coefficient MASS. POINTS is a Np-by-Nd array, MASS is Np-by-1
470 array, and PX and PY are also both Np-by-1 arrays.
474 pts = [2 2;6 1;6 5;2 4];
479 See also: points2d, polygonCentroid
485 # name: <cell-element>
489 Compute centroid (center of mass) of a set of points.
493 # name: <cell-element>
500 # name: <cell-element>
504 -- Function File: P = circleArcAsCurve (ARC, N)
505 Convert a circle arc into a series of points
507 P = circleArcAsCurve(ARC, N); convert the circle ARC into a
508 series of N points. ARC is given in the format: [XC YC R THETA1
509 DTHETA] where XC and YC define the center of the circle, R its
510 radius, THETA1 is the start of the arc and DTHETA is the angle
511 extent of the arc. Both angles are given in degrees. N is the
512 number of vertices of the resulting polyline, default is 65.
514 The result is a N-by-2 array containing coordinates of the N
517 [X Y] = circleArcAsCurve(ARC, N); Return the result in two
518 separate arrays with N lines and 1 column.
520 See also: circles2d, circleAsPolygon, drawCircle, drawPolygon
526 # name: <cell-element>
530 Convert a circle arc into a series of points
535 # name: <cell-element>
542 # name: <cell-element>
546 -- Function File: P = circleAsPolygon (CIRCLE, N)
547 Convert a circle into a series of points
549 P = circleAsPolygon(CIRCLE, N); convert circle given as [x0 y0
550 r], where x0 and y0 are coordinate of center, and r is the
551 radius, into an array of [(N+1)x2] double, containing x and y
552 values of points. The polygon is closed
554 P = circleAsPolygon(CIRCLE); uses a default value of N=64 points
556 Example circle = circleAsPolygon([10 0 5], 16); figure;
559 See also: circles2d, polygons2d, createCircle
565 # name: <cell-element>
569 Convert a circle into a series of points
574 # name: <cell-element>
581 # name: <cell-element>
585 -- Function File: circles2d ()
586 Description of functions operating on circles
588 Circles are represented by their center and their radius: C =
589 [xc yc r]; One sometimes considers orientation of circle, by
590 adding an extra boolean value in 4-th position, with value TRUE
591 for direct (i.e. turning Counter-clockwise) circles.
593 Circle arcs are represented by their center, their radius, the
594 starting angle and the angle extent, both in degrees: CA = [xc
597 Ellipses are represented by their center, their 2 semi-axis
598 length, and their angle (in degrees) with Ox direction. E =
601 See also: ellipses2d, createCircle, createDirectedCircle,
602 enclosingCircle isPointInCircle, isPointOnCircle
603 intersectLineCircle, intersectCircles, radicalAxis
604 circleAsPolygon, circleArcAsCurve drawCircle, drawCircleArc
610 # name: <cell-element>
614 Description of functions operating on circles
619 # name: <cell-element>
626 # name: <cell-element>
630 -- Function File: EDGE2 = clipEdge (EDGE, BOX)
631 Clip an edge with a rectangular box.
633 EDGE: [x1 y1 x2 y2], BOX : [xmin xmax ; ymin ymax] or [xmin xmax
634 ymin ymax]; return : EDGE2 = [xc1 yc1 xc2 yc2];
636 If clipping is null, return [0 0 0 0];
638 if EDGE is a [nx4] array, return an [nx4] array, corresponding to
641 See also: edges2d, boxes2d, clipLine
647 # name: <cell-element>
651 Clip an edge with a rectangular box.
655 # name: <cell-element>
662 # name: <cell-element>
666 -- Function File: EDGE = clipLine (LINE, BOX)
667 Clip a line with a box.
669 LINE is a straight line given as a 4 element row vector: [x0 y0 dx
670 dy], with (x0 y0) being a point of the line and (dx dy) a
671 direction vector, BOX is the clipping box, given by its extreme
672 coordinates: [xmin xmax ymin ymax]. The result is given as an
673 edge, defined by the coordinates of its 2 extreme points: [x1 y1
674 x2 y2]. If line does not intersect the box, [NaN NaN NaN NaN]
677 Function works also if LINE is a Nx4 array, if BOX is a Nx4 array,
678 or if both LINE and BOX are Nx4 arrays. In these cases, EDGE is
685 res = clipLine(line, box)
689 See also: lines2d, boxes2d, edges2d, clipEdge, clipRay
695 # name: <cell-element>
699 Clip a line with a box.
703 # name: <cell-element>
710 # name: <cell-element>
714 -- Function File: POINTS2 = clipPoints (POINTS, BOX)
715 Clip a set of points by a box.
717 Returns the set POINTS2 which are located inside of the box BOX.
719 See also: points2d, boxes2d, clipLine, drawPoint
725 # name: <cell-element>
729 Clip a set of points by a box.
733 # name: <cell-element>
740 # name: <cell-element>
744 -- Function File: [EDGE INSIDE] = clipRay (RAY, BOX)
745 Clip a ray with a box.
747 RAY is a straight ray given as a 4 element row vector: [x0 y0 dx
748 dy], with (x0 y0) being the origin of the ray and (dx dy) its
749 direction vector, BOX is the clipping box, given by its extreme
750 coordinates: [xmin xmax ymin ymax]. The result is given as an
751 edge, defined by the coordinates of its 2 extreme points: [x1 y1
752 x2 y2]. If the ray does not intersect the box, [NaN NaN NaN
755 Function works also if RAY is a Nx4 array, if BOX is a Nx4 array,
756 or if both RAY and BOX are Nx4 arrays. In these cases, EDGE is a
759 See also: rays2d, boxes2d, edges2d, clipLine, drawRay
765 # name: <cell-element>
769 Clip a ray with a box.
773 # name: <cell-element>
780 # name: <cell-element>
784 -- Function File: Y = polygon (X)
785 Returns a simple closed path that passes through all the points in
786 X. X is a vector containing 2D coordinates of the points.
792 # name: <cell-element>
796 Returns a simple closed path that passes through all the points in X.
800 # name: <cell-element>
807 # name: <cell-element>
811 -- Function File: ELLIPSE = cov2ellipse (K)
812 -- Function File: [RA RB THETA] = cov2ellipse (K)
813 -- Function File: ... = cov2ellipse (..., `tol',TOL)
814 Calculates ellipse parameters from covariance matrix.
816 K must be symmetric positive (semi)definite. The optional argument
817 `tol' sets the tolerance for the verification of the
818 positive-(semi)definiteness of the matrix K (see `isdefinite').
820 If only one output argument is supplied a vector defining a
821 ellipse is returned as defined in `ellipses2d'. Otherwise the
822 angle THETA is given in radians.
824 Run `demo cov2ellipse' to see an example.
826 See also: ellipses2d, cov2ellipse, drawEllipse
832 # name: <cell-element>
836 Calculates ellipse parameters from covariance matrix.
840 # name: <cell-element>
847 # name: <cell-element>
851 -- Function File: E = crackPattern (BOX, POINTS, ALPHA)
852 Create a (bounded) crack pattern tessellation
854 E = crackPattern2(BOX, POINTS, ALPHA) create a crack propagation
855 pattern wit following parameters : - pattern is bounded by area
856 BOX which is a polygon. - each crack originates from points
857 given in POINTS - directions of each crack is given by a [NxM]
858 array ALPHA, where M is the number of rays emanating from each
859 seed/ - a crack stop when it reaches another already created
860 crack. - all cracks stop when they reach the border of the
861 frame, given by box (a serie of 4 points). The result is a
862 collection of edges, in the form [x1 y1 x2 y2].
864 E = crackPattern2(BOX, POINTS, ALPHA, SPEED) Also specify speed
865 of propagation of each crack.
867 See the result with : figure; drawEdge(E);
875 # name: <cell-element>
879 Create a (bounded) crack pattern tessellation
884 # name: <cell-element>
891 # name: <cell-element>
895 -- Function File: E = crackPattern2 (BOX, POINTS, ALPHA)
896 Create a (bounded) crack pattern tessellation
898 E = crackPattern2(BOX, POINTS, ALPHA) create a crack propagation
899 pattern wit following parameters : - pattern is bounded by area
900 BOX which is a polygon. - each crack originates from points
901 given in POINTS - directions of each crack is given by a [NxM]
902 array ALPHA, where M is the number of rays emanating from each
903 seed/ - a crack stop when it reaches another already created
904 crack. - all cracks stop when they reach the border of the
905 frame, given by box (a serie of 4 points). The result is a
906 collection of edges, in the form [x1 y1 x2 y2].
908 E = crackPattern2(BOX, POINTS, ALPHA, SPEED) Also specify speed
909 of propagation of each crack.
911 See the result with : figure; drawEdge(E);
919 # name: <cell-element>
923 Create a (bounded) crack pattern tessellation
928 # name: <cell-element>
935 # name: <cell-element>
939 -- Function File: T = createBasisTransfrom (TARGET)
940 -- Function File: T = createBasisTransfrom (SOURCE, TARGET)
941 Compute matrix for transforming a basis into another basis
943 With only one input arguemnt, assumes the SOURCE is the standard
944 (Oij) basis, with origin at (0,0), first direction vector equal
945 to (1,0) and second direction vector equal to (0,1). Otherwise
946 SOURCE specifies the SOURCE basis.
948 Both SOURCE and TARGET represent basis, in the following form:
949 [x0 y0 ex1 ey1 ex2 ey2] [y0 y0] is the origin of the basis,
950 [ex1 ey1] is the first direction vector, and [ex2 ey2] is the
951 second direction vector.
953 The result T is a 3-by-3 matrix such that a point expressed with
954 coordinates of the first basis will be represented by new
955 coordinates `P2 = transformPoint(P1, T)' in the TARGET basis.
958 % standard basis transform
960 % TARGET transform, just a rotation by atan(2/3) followed by a scaling
961 tgt = [0 0 .75 .5 -.5 .75];
963 trans = createBasisTransform(src, tgt);
964 % transform the point (.25,1.25) into the point (1,1)
966 p2 = transformPoint(p1, trans)
970 See also: transforms2d
976 # name: <cell-element>
980 Compute matrix for transforming a basis into another basis
985 # name: <cell-element>
992 # name: <cell-element>
996 -- Function File: CIRCLE = createCircle (P1, P2, P3)
997 -- Function File: CIRCLE = createCircle (P1, P2)
998 Create a circle from 2 or 3 points.
1000 Creates the circle passing through the 3 given points. C is a
1001 1x3 array of the form: [XC YX R].
1003 When two points are given, creates the circle whith center P1 and
1004 passing throuh the point P2.
1006 Works also when input are point arrays the same size, in this case
1007 the result has as many lines as the point arrays.
1011 % Draw a circle passing through 3 points.
1015 circle = createCircle(p1, p2, p3);
1016 figure; hold on; axis equal; axis([0 50 0 50]);
1017 drawPoint([p1 ; p2; p3]);
1020 See also: circles2d, createDirectedCircle
1026 # name: <cell-element>
1030 Create a circle from 2 or 3 points.
1034 # name: <cell-element>
1038 createDirectedCircle
1041 # name: <cell-element>
1045 -- Function File: CIRCLE = createDirectedCircle (P1, P2, P3)
1046 -- Function File: CIRCLE = createDirectedCircle (P1, P2)
1047 Create a circle from 2 or 3 points.
1049 Creates the circle passing through the 3 given points. C is a
1050 1x4 array of the form: [XC YX R INV].
1052 When two points are given, creates the circle whith center P1 and
1053 passing throuh the point P2.
1055 Works also when input are point arrays the same size, in this case
1056 the result has as many lines as the point arrays.
1060 See also: circles2d, createCircle
1066 # name: <cell-element>
1070 Create a circle from 2 or 3 points.
1074 # name: <cell-element>
1081 # name: <cell-element>
1085 -- Function File: EDGE = createEdge (P1, P2)
1086 -- Function File: EDGE = createEdge (X0, Y0, DX, DY)
1087 -- Function File: EDGE = createEdge (PARAM)
1088 -- Function File: EDGE = createEdge (LINE, D)
1089 Create an edge between two points, or from a line.
1091 The internal format for edge representation is given by
1092 coordinates of two points : [x1 y1 x2 y2]. This function can
1093 serve as a line to edge converter.
1095 Returns the edge between the two given points P1 and P2.
1097 Returns the edge going through point (X0, Y0) and with direction
1100 When PARAM is an array of 4 values, creates the edge going through
1101 the point (param(1) param(2)), and with direction vector given by
1102 (param(3) param(4)).
1104 When LINE is given, creates the edge contained in LINE, with same
1105 direction and start point, but with length given by D.
1107 Note: in all cases, parameters can be vertical arrays of the same
1108 dimension. The result is then an array of edges, of dimensions
1111 See also: edges2d, lines2d, drawEdge, clipEdge
1117 # name: <cell-element>
1121 Create an edge between two points, or from a line.
1125 # name: <cell-element>
1132 # name: <cell-element>
1136 -- Function File: T = createHomothecy (POINT, RATIO)
1137 Create the the 3x3 matrix of an homothetic transform.
1139 POINT is the center of the homothecy, RATIO is its factor.
1141 See also: transforms2d, transformPoint, createTranslation
1147 # name: <cell-element>
1151 Create the the 3x3 matrix of an homothetic transform.
1155 # name: <cell-element>
1162 # name: <cell-element>
1166 -- Function File: LINE = createLine(varargin)
1167 Create a straight line from 2 points, or from other inputs
1169 Line is represented in a parametric form : [x0 y0 dx dy] x = x0
1170 + t*dx y = y0 + t*dy;
1172 L = createLine(p1, p2); Returns the line going through the two
1175 L = createLine(x0, y0, dx, dy); Returns the line going through
1176 point (x0, y0) and with direction vector(dx, dy).
1178 L = createLine(LINE); where LINE is an array of 4 values,
1179 creates the line going through the point (LINE(1) LINE(2)), and
1180 with direction given by vector (LINE(3) LINE(4)).
1182 L = createLine(THETA); Create a polar line originated at (0,0)
1183 and with angle THETA.
1185 L = createLine(RHO, THETA); Create a polar line with normal
1186 theta, and with min distance to origin equal to rho. rho can be
1187 negative, in this case, the line is the same as with
1188 CREATELINE(-rho, theta+pi), but the orientation is different.
1190 Note: in all cases, parameters can be vertical arrays of the same
1191 dimension. The result is then an array of lines, of dimensions
1194 NOTE : A line can also be represented with a 1*5 array : [x0 y0
1195 dx dy t]. whith 't' being one of the following : - t=0 : line
1196 is a singleton (x0,y0) - t=1 : line is an edge segment, between
1197 points (x0,y0) and (x0+dx, y0+dy). - t=Inf : line is a Ray,
1198 originated from (x0,y0) and going to infinity in the
1199 direction(dx,dy). - t=-Inf : line is a Ray, originated from
1200 (x0,y0) and going to infinity in the direction(-dx,-dy). -
1201 t=NaN : line is a real straight line, and contains all points
1202 verifying the above equation. This seems us a convenient way to
1203 represent uniformly all kind of lines (including edges, rays,
1206 NOTE2 : Any line object can be represented using a 1x6 array :
1207 [x0 y0 dx dy t0 t1] the first 4 parameters define the supporting
1208 line, t0 represent the position of the first point on the line,
1209 and t1 the position of the last point. * for edges : t0 = 0,
1210 and t1=1 * for straight lines : t0 = -inf, t1=inf * for rays :
1211 t0=0, t1=inf (or t0=-inf,t1=0 for inverted ray). I propose to
1212 call these objects 'lineArc'
1214 See also: lines2d, createEdge, createRay
1220 # name: <cell-element>
1224 Create a straight line from 2 points, or from other inputs
1229 # name: <cell-element>
1233 createLineReflection
1236 # name: <cell-element>
1240 -- Function File: T = function_name (LINE)
1241 Create the the 3x3 matrix of a line reflection.
1243 Where LINE is given as [x0 y0 dx dy], return the affine tansform
1244 corresponding to the desired line reflection.
1246 See also: lines2d, transforms2d, transformPoint,
1247 createTranslation, createHomothecy, createScaling
1253 # name: <cell-element>
1257 Create the the 3x3 matrix of a line reflection.
1261 # name: <cell-element>
1268 # name: <cell-element>
1272 -- Function File: RAY = createRay (POINT, ANGLE)
1273 -- Function File: RAY = createRay (X0,Y0, ANGLE)
1274 -- Function File: RAY = createRay (P1, P2)
1275 Create a ray (half-line), from various inputs.
1277 A Ray is represented in a parametric form: [x0 y0 dx dy]. x =
1278 x0 + t*dx y = y0 + t*dy; for all t>0.
1280 POINT is a Nx2 array giving the starting point of the ray, and
1281 ANGLE is the orientation of the ray respect to the positive
1282 x-axis. The ray origin can be specified with 2 input arguments
1285 If two points P1, P2 are given, creates a ray starting from point
1286 P1 and going in the direction of point P2.
1291 ray = createRay(origin, theta);
1295 See also: rays2d, createLine, points2d
1301 # name: <cell-element>
1305 Create a ray (half-line), from various inputs.
1309 # name: <cell-element>
1316 # name: <cell-element>
1320 -- Function File: T = createRotation (THETA)
1321 -- Function File: T = createRotation (POINT, THETA)
1322 -- Function File: T = createRotation (X0, Y0, THETA)
1323 Create the 3*3 matrix of a rotation.
1325 Returns the rotation corresponding to angle THETA (in radians)
1326 The returned matrix has the form : [cos(theta) -sin(theta) 0]
1327 [sin(theta) cos(theta) 0] [0 0 1]
1329 POINT or (X0,Y0), specifies origin of rotation. The result is
1330 similar as performing translation(-X0,-Y0), rotation(THETA), and
1333 See also: transforms2d, transformPoint, createTranslation,
1340 # name: <cell-element>
1344 Create the 3*3 matrix of a rotation.
1348 # name: <cell-element>
1355 # name: <cell-element>
1359 -- Function File: T = createScaling (S)
1360 -- Function File: T = createScaling (SX, SY)
1361 Create the 3x3 matrix of a scaling in 2 dimensions.
1363 Assume scaling S is equal n all directions unless SX and SY are
1364 given. Returns the matrix corresponding to scaling in the 2
1365 main directions. The returned matrix has the form: [SX 0 0]
1368 See also: transforms2d, transformPoint, createTranslation,
1375 # name: <cell-element>
1379 Create the 3x3 matrix of a scaling in 2 dimensions.
1383 # name: <cell-element>
1390 # name: <cell-element>
1394 -- Function File: T = createTranslation (VECTOR)
1395 -- Function File: T = createTranslation (DX,DY)
1396 Create the 3*3 matrix of a translation.
1398 Returns the matrix corresponding to a translation by the vector
1399 [DX DY]. The components can be given as two arguments. The
1400 returned matrix has the form : [1 0 TX] [0 1 TY] [0 0 1]
1402 See also: transforms2d, transformPoint, createRotation,
1409 # name: <cell-element>
1413 Create the 3*3 matrix of a translation.
1417 # name: <cell-element>
1424 # name: <cell-element>
1428 -- Function File: VECT = createVector (P1, P2)
1429 Create a vector from two points.
1431 V12 = createVector(P1, P2) Creates the vector V12, defined as
1432 the difference between coordinates of points P1 and P2. P1
1433 and P2 are row vectors with ND elements, ND being the space
1436 If one of the inputs is a N-by-Nd array, the other input is
1437 automatically repeated, and the result is N-by-Nd.
1439 If both inputs have the same size, the result also have the same
1442 See also: vectors2d, vectors3d, points2d
1448 # name: <cell-element>
1452 Create a vector from two points.
1456 # name: <cell-element>
1463 # name: <cell-element>
1467 -- Function File: RAD = deg2rad(DEG)
1468 Convert angle from degrees to radians
1470 Usage: R = deg2rad(D) convert an angle in degrees to an angle
1473 Example deg2rad(180) % gives pi ans = 3.1416
1474 deg2rad(60) % gives pi/3 ans = 1.0472
1476 See also: angles2d, rad2deg
1482 # name: <cell-element>
1486 Convert angle from degrees to radians
1491 # name: <cell-element>
1498 # name: <cell-element>
1502 -- Function File: DIST = distancePointEdge (POINT, EDGE)
1503 -- Function File: DIST = distancePointEdge (..., OPT)
1504 -- Function File: [DIST POS]= distancePointEdge (...)
1505 Minimum distance between a point and an edge
1507 Return the euclidean distance between edge EDGE and point POINT.
1508 EDGE has the form: [x1 y1 x2 y2], and POINT is [x y]. If EDGE is
1509 Ne-by-4 and POINT is Np-by-2, then DIST is Np-by-Ne, where each
1510 row contains the distance of each point to all the edges.
1512 If OPT is true (or equivalent), the optput is cmpatible with the
1515 If POINT is 1-by-2 array, the result is Ne-by-1 array
1516 computed for each edge.
1519 If EDGE is a 1-by-4 array, the result is Np-by-1 computed for
1523 If both POINT and EDGE are array, they must have the same
1524 number of rows, and the result is computed for each couple
1525 `POINT(i,:),EDGE(i,:)'.
1527 If the the second output argument POS is requested, the function
1528 also returns the position of closest point on the edge. POS is
1529 comprised between 0 (first point) and 1 (last point).
1531 See also: edges2d, points2d, distancePoints, distancePointLine
1537 # name: <cell-element>
1541 Minimum distance between a point and an edge
1546 # name: <cell-element>
1553 # name: <cell-element>
1557 -- Function File: DIST = distancePointLine (POINT, LINE)
1558 Minimum distance between a point and a line
1560 D = distancePointLine(POINT, LINE) Return the euclidean distance
1561 between line LINE and point POINT.
1563 LINE has the form : [x0 y0 dx dy], and POINT is [x y].
1565 If LINE is N-by-4 array, result is N-by-1 array computes for each
1568 If POINT is N-by-2, then result is computed for each point.
1570 If both POINT and LINE are array, result is N-by-1, computed for
1571 each corresponding point and line.
1573 See also: lines2d, points2d, distancePoints, distancePointEdge
1579 # name: <cell-element>
1583 Minimum distance between a point and a line
1588 # name: <cell-element>
1595 # name: <cell-element>
1599 -- Function File: D = distancePoints (P1, P2)
1600 -- Function File: D = distancePoints (P1, P2, NORM)
1601 -- Function File: D = distancePoints (..., 'diag')
1602 Compute distance between two points.
1604 Returns the Euclidean distance between points P1 and P2. If P1
1605 and P2 are two arrays of points, result is a N1xN2 array
1606 containing distance between each point of P1 and each point of P2.
1608 Is NORM is given, computes distance using the specified norm.
1609 NORM=2 corresponds to usual euclidean distance, NORM=1
1610 corresponds to Manhattan distance, NORM=inf is assumed to
1611 correspond to maximum difference in coordinate. Other values
1612 (>0) can be specified.
1614 When 'diag' is given, computes only distances between P1(i,:) and
1617 See also: points2d, minDistancePoints
1623 # name: <cell-element>
1627 Compute distance between two points.
1631 # name: <cell-element>
1638 # name: <cell-element>
1642 -- Function File: H = drawArrow (X1, Y1, X2, Y2)
1643 -- Function File: H = drawArrow ([ X1 Y1 X2 Y2])
1644 -- Function File: H = drawArrow (..., L, W)
1645 -- Function File: H = drawArrow (..., L, W,TYPE)
1646 Draw an arrow on the current axis.
1648 draw an arrow between the points (X1 Y1) and (X2 Y2). The points
1649 can be given as a single array. L, W specify length and width of
1652 Also specify arrow type. TYPE can be one of the following : 0:
1653 draw only two strokes 1: fill a triangle .5: draw a half arrow
1656 Arguments can be single values or array of size [N*1]. In this
1657 case, the function draws multiple arrows.
1663 # name: <cell-element>
1667 Draw an arrow on the current axis.
1671 # name: <cell-element>
1678 # name: <cell-element>
1682 -- Function File: drawBezierCurve (POINTS)
1683 -- Command: Function File drawBezierCurve (PP)
1684 -- Command: Function File drawBezierCurve (..., PARAM, VALUE, ...)
1685 -- Command: Function File H =drawBezierCurve (...)
1686 Draw a cubic bezier curve defined by the control points POINTS.
1688 With only one input argument, draws the Bezier curve defined by
1689 the 4 control points stored in POINTS. POINTS is either a 4-by-2
1690 array (vertical concatenation of point coordinates), or a 1-by-8
1691 array (horizotnal concatenation of point coordinates). The curve
1692 could be described by its polynomial (output of `cbezier2poly')
1693 PP, which should be a 2-by-4 array.
1695 The optional PARAM, VALUE pairs specify additional drawing
1696 parameters, see the `plot' function for details. The specific
1697 parameter 'discretization' with an integer associated value
1698 defines the amount of points used to plot the curve. If the output
1699 is requiered, the function returns the handle to the created
1702 See also: cbezier2poly, plot
1708 # name: <cell-element>
1712 Draw a cubic bezier curve defined by the control points POINTS.
1716 # name: <cell-element>
1723 # name: <cell-element>
1727 -- Function File: H = drawBox (BOX)
1728 -- Function File: H = drawBox (BOX, PARAM, VALUE, ...)
1729 Draw a box defined by coordinate extents
1731 Draws a box defined by its extent: BOX = [XMIN XMAX YMIN YMAX].
1732 Addtional arguments are passed to function `plot'. If requested,
1733 it returns the handle to the graphics object created.
1735 See also: drawOrientedBox, drawRect, plot
1741 # name: <cell-element>
1745 Draw a box defined by coordinate extents
1750 # name: <cell-element>
1757 # name: <cell-element>
1761 -- Function File: H = drawCenteredEdge (CENTER, L, THETA)
1762 -- Function File: H = drawCenteredEdge (EDGE)
1763 -- Function File: H = drawCenteredEdge (..., NAME,VALUE)
1764 Draw an edge centered on a point.
1766 drawCenteredEdge(CENTER, L, THETA) Draws an edge centered on
1767 point CENTER, with length L, and orientation THETA (given in
1768 degrees). Input arguments can also be arrays, that must all have
1769 the same number odf rows.
1771 drawCenteredEdge(EDGE) Concatenates edge parameters into a
1772 single N-by-4 array, containing: [XC YV L THETA].
1774 drawCenteredEdge(..., NAME, VALUE) Also specifies drawing
1775 options by using one or several parameter name - value pairs
1776 (see doc of plot function for details).
1778 H = drawCenteredEdge(...) Returns handle(s) to the created
1781 % Draw an ellipse with its two axes
1786 elli = [center r1 r2 theta];
1787 drawEllipse(elli, 'linewidth', 2);
1788 axis([0 100 0 100]); axis equal;
1790 edges = [center 2*r1 theta ; center 2*r2 theta+90];
1791 drawCenteredEdge(edges, 'linewidth', 2, 'color', 'g');
1793 See also: edges2d, drawEdge
1799 # name: <cell-element>
1803 Draw an edge centered on a point.
1807 # name: <cell-element>
1814 # name: <cell-element>
1818 -- Function File: H = drawCircle (X0, Y0, R)
1819 -- Function File: H = drawCircle (CIRCLE)
1820 -- Function File: H = drawCircle (CENTER, RADIUS)
1821 -- Function File: H = drawCircle (..., NSTEP)
1822 -- Function File: H = drawCircle (..., NAME, VALUE)
1823 Draw a circle on the current axis
1825 drawCircle(X0, Y0, R); Draw the circle with center (X0,Y0) and
1826 the radius R. If X0, Y0 and R are column vectors of the same
1827 length, draw each circle successively.
1829 drawCircle(CIRCLE); Concatenate all parameters in a Nx3 array,
1830 where N is the number of circles to draw.
1832 drawCircle(CENTER, RADIUS); Specify CENTER as Nx2 array, and
1833 radius as a Nx1 array.
1835 drawCircle(..., NSTEP); Specify the number of edges that will be
1836 used to draw the circle. Default value is 72, creating an
1837 approximation of one point for each 5 degrees.
1839 drawCircle(..., NAME, VALUE); Specifies plotting options as pair
1840 of parameters name/value. See plot documentation for details.
1842 H = drawCircle(...); return handles to each created curve.
1844 See also: circles2d, drawCircleArc, drawEllipse
1850 # name: <cell-element>
1854 Draw a circle on the current axis
1859 # name: <cell-element>
1866 # name: <cell-element>
1870 -- Function File: H = drawCircleArc (XC, YC, R, START, END)
1871 -- Function File: H = drawCircleArc (ARC)
1872 -- Function File: H = drawCircleArc (..., PARAM, VALUE)
1873 Draw a circle arc on the current axis
1875 drawCircleArc(XC, YC, R, START, EXTENT); Draws circle with
1876 center (XC, YC), with radius R, starting from angle START, and
1877 with angular extent given by EXTENT. START and EXTENT angles are
1880 drawCircleArc(ARC); Puts all parameters into one single array.
1882 drawCircleArc(..., PARAM, VALUE); specifies plot properties by
1883 using one or several parameter name-value pairs.
1885 H = drawCircleArc(...); Returns a handle to the created line
1888 % Draw a red thick circle arc
1889 arc = [10 20 30 -120 240];
1891 axis([-50 100 -50 100]);
1893 drawCircleArc(arc, 'LineWidth', 3, 'Color', 'r')
1895 See also: circles2d, drawCircle, drawEllipse
1901 # name: <cell-element>
1905 Draw a circle arc on the current axis
1910 # name: <cell-element>
1917 # name: <cell-element>
1921 -- Function File: H = drawEdge (X1, Y1, X2, Y2)
1922 -- Function File: H = drawEdge ([X1 Y1 X2 Y2])
1923 -- Function File: H = drawEdge ([X1 Y1], [X2 Y2])
1924 -- Function File: H = drawEdge (X1, Y1, Z1, X2, Y2, Z2)
1925 -- Function File: H = drawEdge ([X1 Y1 Z1 X2 Y2 Z2])
1926 -- Function File: H = drawEdge ([X1 Y1 Z1], [X2 Y2 Z2])
1927 -- Function File: H = drawEdge (..., OPT)
1928 Draw an edge given by 2 points.
1930 Draw an edge between the points (x1 y1) and (x2 y2). Data can be
1931 bundled as an edge. The function supports 3D edges.
1932 Arguments can be single values or array of size [Nx1]. In this
1933 case, the function draws multiple edges. OPT, being a set of
1934 pairwise options, can specify color, line width and so on. These
1935 are passed to function `line'. The function returns handle(s)
1936 to created edges(s).
1938 See also: edges2d, drawCenteredEdge, drawLine, line
1944 # name: <cell-element>
1948 Draw an edge given by 2 points.
1952 # name: <cell-element>
1959 # name: <cell-element>
1963 -- Function File: H = drawEllipse (ELLI)
1964 -- Function File: H = drawEllipse (XC, YC, RA, RB)
1965 -- Function File: H = drawEllipse (XC, YC, RA, RB, THETA)
1966 -- Function File: H = drawEllipse (..., PARAM, VALUE)
1967 Draw an ellipse on the current axis.
1969 drawEllipse(ELLI); Draws the ellipse ELLI in the form [XC YC RA
1970 RB THETA], with center (XC, YC), with main axis of half-length
1971 RA and RB, and orientation THETA in degrees counted
1972 counter-clockwise. Puts all parameters into one single array.
1974 drawEllipse(XC, YC, RA, RB); drawEllipse(XC, YC, RA, RB, THETA);
1975 Specifies ellipse parameters as separate arguments (old syntax).
1977 drawEllipse(..., NAME, VALUE); Specifies drawing style of
1978 ellipse, see the help of plot function.
1980 H = drawEllipse(...); Also returns handles to the created line
1983 -> Parameters can also be arrays. In this case, all arrays are
1984 supposed to have the same size.
1987 % Draw an ellipse centered in [50 50], with semi major axis length of
1988 % 40, semi minor axis length of 20, and rotated by 30 degrees.
1989 figure(1); clf; hold on;
1990 drawEllipse([50 50 40 20 30]);
1993 See also: ellipses2d, drawCircle, drawEllipseArc, ellipseAsPolygon
1999 # name: <cell-element>
2003 Draw an ellipse on the current axis.
2007 # name: <cell-element>
2014 # name: <cell-element>
2018 -- Function File: H = drawEllipseArc (ARC)
2019 Draw an ellipse arc on the current axis.
2021 drawEllipseArc(ARC) draw ellipse arc specified by ARC. ARC has
2022 the format: ARC = [XC YC A B THETA T1 T2] or: ARC = [XC
2023 YC A B T1 T2] (isothetic ellipse) with center (XC, YC), main
2024 axis of half-length A, second axis of half-length B, and ellipse
2025 arc running from t1 to t2 (both in degrees, in Counter-Clockwise
2028 Parameters can also be arrays. In this case, all arrays are
2029 suposed to have the same size...
2031 % draw an ellipse arc: center = [10 20], radii = 50 and 30, theta = 45
2032 arc = [10 20 50 30 45 -90 270];
2034 axis([-50 100 -50 100]); axis equal;
2036 drawEllipseArc(arc, 'color', 'r')
2038 % draw another ellipse arc, between angles -60 and 70
2039 arc = [10 20 50 30 45 -60 (60+70)];
2041 axis([-50 100 -50 100]); axis equal;
2043 drawEllipseArc(arc, 'LineWidth', 2);
2044 ray1 = createRay([10 20], deg2rad(-60+45));
2046 ray2 = createRay([10 20], deg2rad(70+45));
2049 See also: ellipses2d, drawEllipse, drawCircleArc
2055 # name: <cell-element>
2059 Draw an ellipse arc on the current axis.
2063 # name: <cell-element>
2070 # name: <cell-element>
2074 -- Function File: drawLabels (X, Y, LBL)
2075 -- Function File: drawLabels (POS, LBL)
2076 -- Function File: drawLabels (..., NUMBERS, FORMAT)
2077 Draw labels at specified positions.
2079 DRAWLABELS(X, Y, LBL) draw labels LBL at position X and Y. LBL
2080 can be either a string array, or a number array. In this case,
2081 string are created by using sprintf function, with '%.2f' mask.
2083 DRAWLABELS(POS, LBL) draw labels LBL at position specified by POS,
2084 where POS is a N*2 int array.
2086 DRAWLABELS(..., NUMBERS, FORMAT) create labels using sprintf
2087 function, with the mask given by FORMAT (e. g. '%03d' or
2088 '5.3f'), and the corresponding values.
2093 # name: <cell-element>
2097 Draw labels at specified positions.
2101 # name: <cell-element>
2108 # name: <cell-element>
2112 -- Function File: H = drawLine (LINE)
2113 -- Function File: H = drawLine (LINE, PARAM,VALUE)
2114 Draw the line on the current axis.
2116 Draws the line LINE on the current axis, by using current axis to
2117 clip the line. Extra PARAM,VALUE pairs are passed to the `line'
2118 function. Returns a handle to the created line object. If
2119 clipped line is not contained in the axis, the function returns
2124 figure; hold on; axis equal;
2125 axis([0 100 0 100]);
2126 drawLine([30 40 10 20]);
2127 drawLine([30 40 20 -10], 'color', 'm', 'linewidth', 2);
2129 See also: lines2d, createLine, drawEdge
2135 # name: <cell-element>
2139 Draw the line on the current axis.
2143 # name: <cell-element>
2150 # name: <cell-element>
2154 -- Function File: HB = drawOrientedBox (BOX)
2155 -- Function File: HB = drawOrientedBox (..., PARAM, VALUE)
2156 Draw centered oriented rectangle.
2158 Syntax drawOrientedBox(BOX) drawOrientedBox(BOX,
2159 'PropertyName', propertyvalue, ...)
2161 Description drawOrientedBox(OBOX) Draws an oriented rectangle
2162 (or bounding box) on the current axis. OBOX is a 1-by-5 row
2163 vector containing box center, dimension (length and width) and
2164 orientation (in degrees): OBOX = [CX CY LENGTH WIDTH THETA].
2166 When OBOX is a N-by-5 array, the N boxes are drawn.
2168 HB = drawOrientedBox(...) Returns a handle to the created
2169 graphic object(s). Object style can be modified using syntaw
2170 like: set(HB, 'color', 'g', 'linewidth', 2);
2172 See also: drawPolygon, drawRect, drawBox
2178 # name: <cell-element>
2182 Draw centered oriented rectangle.
2186 # name: <cell-element>
2193 # name: <cell-element>
2197 -- Function File: H = drawParabola (PARABOLA)
2198 -- Function File: H = drawParabola (PARABOLA, T)
2199 -- Function File: H = drawParabola (..., PARAM, VALUE)
2200 Draw a parabola on the current axis.
2202 drawParabola(PARABOLA); Draws a vertical parabola, defined by
2203 its vertex and its parameter. Such a parabola admits a vertical
2206 The algebraic equation of parabola is given by: (Y - YV) = A
2207 * (X - VX)^2 Where XV and YV are vertex coordinates and A is
2210 A parametric equation of parabola is given by: x(t) = t + VX;
2211 y(t) = A * t^2 + VY;
2213 PARABOLA can also be defined by [XV YV A THETA], with theta being
2214 the angle of rotation of the parabola (in degrees and
2217 drawParabola(PARABOLA, T); Specifies which range of 't' are used
2218 for drawing parabola. If T is an array with only two values, the
2219 first and the last values are used as interval bounds, and
2220 several values are distributed within this interval.
2222 drawParabola(..., NAME, VALUE); Can specify one or several
2223 graphical options using parameter name-value pairs.
2225 H = drawParabola(...); Returns an handle to the created
2229 figure(1); clf; hold on;
2230 drawParabola([50 50 .2 30]);
2231 drawParabola([50 50 .2 30], [-1 1], 'color', 'r', 'linewidth', 2);
2234 See also: drawCircle, drawEllipse
2240 # name: <cell-element>
2244 Draw a parabola on the current axis.
2248 # name: <cell-element>
2255 # name: <cell-element>
2259 -- Function File: H = drawPoint (X, Y)
2260 -- Function File: H = drawPoint (COORD)
2261 -- Function File: H = drawPoint (..., OPT)
2262 Draw the point on the axis.
2264 Draws points defined by coordinates X and YY. X and Y should be
2265 array the same size. Coordinates can be packed coordinates in a
2266 single [N*2] array COORD. Options OPT are passed to the `plot'
2269 See also: points2d, clipPoints
2275 # name: <cell-element>
2279 Draw the point on the axis.
2283 # name: <cell-element>
2290 # name: <cell-element>
2294 -- Function File: H = drawRay (RAY)
2295 -- Function File: H = drawRay (RAY, PARAM, VALUE)
2296 Draw a ray on the current axis.
2298 With RAY having the syntax: [x0 y0 dx dy], draws the ray starting
2299 from point (x0 y0) and going to direction (dx dy), clipped with
2300 the current window axis. PARAM, VALUE pairs are passed to
2303 See also: rays2d, drawLine, line
2309 # name: <cell-element>
2313 Draw a ray on the current axis.
2317 # name: <cell-element>
2324 # name: <cell-element>
2328 -- Function File: R = drawRect (X, Y, W, H)
2329 -- Function File: R = drawRect (X, Y, W, H, THETA)
2330 -- Function File: R = drawRect (COORD)
2331 Draw rectangle on the current axis.
2333 r = DRAWRECT(x, y, w, h) draw rectangle with width W and height H,
2334 at position (X, Y). the four corners of rectangle are then :
2335 (X, Y), (X+W, Y), (X, Y+H), (X+W, Y+H).
2337 r = DRAWRECT(x, y, w, h, theta) also specifies orientation for
2338 rectangle. Theta is given in degrees.
2340 r = DRAWRECT(coord) is the same as DRAWRECT(X,Y,W,H), but all
2341 parameters are packed into one array, whose dimensions is 4*1 or
2344 See also: drawBox, drawOrientedBox
2350 # name: <cell-element>
2354 Draw rectangle on the current axis.
2358 # name: <cell-element>
2365 # name: <cell-element>
2369 -- Function File: drawShape (TYPE, PARAM)
2370 -- Function File: drawShape (..., OPTION)
2371 Draw various types of shapes (circles, polygons...).
2373 drawShape(TYPE, PARAM) Draw the shape of type TYPE, specified by
2374 given parameter PARAM. TYPE can be one of 'circle', 'ellipse',
2375 'rect', 'polygon', 'curve' PARAM depend on the type. For
2376 example, if TYPE is 'circle', PARAM will contain [x0 y0 R].
2379 drawShape('circle', [20 10 30]);
2380 Draw circle centered on [20 10] with radius 10.
2381 drawShape('rect', [20 20 40 10 pi/3]);
2382 Draw rectangle centered on [20 20] with length 40 and width 10, and
2383 oriented pi/3 wrt axis Ox.
2385 drawShape(..., OPTION) also specifies drawing options. OPTION
2386 can be 'draw' (default) or 'fill'.
2391 # name: <cell-element>
2395 Draw various types of shapes (circles, polygons.
2399 # name: <cell-element>
2406 # name: <cell-element>
2410 -- Function File: THETA = edgeAngle(EDGE)
2411 Return angle of edge
2413 A = edgeAngle(EDGE) Returns the angle between horizontal,
2414 right-axis and the edge EDGE. Angle is given in radians,
2415 between 0 and 2*pi, in counter-clockwise direction. Notation
2416 for edge is [x1 y1 x2 y2] (coordinates of starting and ending
2419 Example p1 = [10 20]; p2 = [30 40]; rad2deg(edgeAngle([p1
2422 See also: edges2d, angles2d, edgeAngle, lineAngle, edgeLength
2428 # name: <cell-element>
2432 Return angle of edge
2437 # name: <cell-element>
2444 # name: <cell-element>
2448 -- Function File: LEN = edgeLength (EDGE)
2449 Return length of an edge
2451 L = edgeLength(EDGE); Returns the length of an edge, with
2452 parametric representation: [x1 y1 x2 y2].
2454 The function also works for several edges, in this case input is a
2455 [N*4] array, containing parametric representation of each edge,
2456 and output is a [N*1] array containing length of each edge.
2458 See also: edges2d, edgeAngle
2464 # name: <cell-element>
2468 Return length of an edge
2473 # name: <cell-element>
2480 # name: <cell-element>
2484 -- Function File: D = edgePosition (POINT, EDGE)
2485 Return position of a point on an edge
2487 POS = edgePosition(POINT, EDGE); Computes position of point
2488 POINT on the edge EDGE, relative to the position of edge
2489 vertices. EDGE has the form [x1 y1 x2 y2], POINT has the form
2490 [x y], and is assumed to belong to edge. The position POS has
2491 meaning: POS<0: POINT is located before the first vertex
2492 POS=0: POINT is located on the first vertex 0<POS<1: POINT
2493 is located between the 2 vertices (on the edge) POS=1:
2494 POINT is located on the second vertex POS<0: POINT is
2495 located after the second vertex
2497 POS = edgePosition(POINT, EDGES); If EDGES is an array of NL
2498 edges, return NL positions, corresponding to each edge.
2500 POS = edgePosition(POINTS, EDGE); If POINTS is an array of NP
2501 points, return NP positions, corresponding to each point.
2503 POS = edgePosition(POINTS, EDGES); If POINTS is an array of NP
2504 points and edgeS is an array of NL edges, return an array of [NP
2505 NL] position, corresponding to each couple point-edge.
2507 See also: edges2d, createEdge, onEdge
2513 # name: <cell-element>
2517 Return position of a point on an edge
2522 # name: <cell-element>
2529 # name: <cell-element>
2533 -- Function File: LINE = edgeToLine (EDGE)
2534 Convert an edge to a straight line
2536 LINE = edgeToLine(EDGE); Returns the line containing the edge
2539 Example edge = [2 3 4 5]; line = edgeToLine(edge);
2540 figure(1); hold on; axis([0 10 0 10]); drawLine(line,
2541 'color', 'g') drawEdge(edge, 'linewidth', 2)
2543 See also: edges2d, lines2d
2549 # name: <cell-element>
2553 Convert an edge to a straight line
2558 # name: <cell-element>
2565 # name: <cell-element>
2569 -- Function File: edges2d ()
2570 Description of functions operating on planar edges
2572 An edge is represented by the corodinate of its end points: EDGE
2575 A set of edges is represented by a N*4 array, each row
2576 representing an edge.
2578 See also: lines2d, rays2d, points2d createEdge, edgeAngle,
2579 edgeLength, edgeToLine, midPoint intersectEdges,
2580 intersectLineEdge, isPointOnEdge clipEdge, transformEdge
2581 drawEdge, drawCenteredEdge
2587 # name: <cell-element>
2591 Description of functions operating on planar edges
2596 # name: <cell-element>
2603 # name: <cell-element>
2607 -- Function File: K = ellipse2cov (ELLI)
2608 -- Function File: K = ellipse2cov (RA, RB)
2609 -- Function File: K = ellipse2cov (..., THETA)
2610 Calculates covariance matrix from ellipse.
2612 If only one input is given, ELLI must define an ellipse as
2613 described in `ellipses2d'. If two inputs are given, RA and RB
2614 define the half-lenght of the axes. If a third input is given,
2615 THETA must be the angle of rotation of the ellipse in radians, and
2616 in counter-clockwise direction.
2618 The output K contains the covariance matrix define by the ellipse.
2620 Run `demo ellipse2cov' to see an example.
2622 See also: ellipses2d, cov2ellipse, drawEllipse
2628 # name: <cell-element>
2632 Calculates covariance matrix from ellipse.
2636 # name: <cell-element>
2643 # name: <cell-element>
2647 -- Function File: P = ellipseAsPolygon (ELL, N)
2648 Convert an ellipse into a series of points
2650 P = ellipseAsPolygon(ELL, N); converts ELL given as [x0 y0 a b]
2651 or [x0 y0 a b theta] into a polygon with N edges. The result P
2652 is (N+1)-by-2 array containing coordinates of the N+1 vertices
2653 of the polygon. The resulting polygon is closed, i.e. the last
2654 point is the same as the first one.
2656 P = ellipseAsPolygon(ELL); Use a default number of edges equal
2657 to 72. This result in one piont for each 5 degrees.
2659 [X Y] = ellipseAsPolygon(...); Return the coordinates o
2660 fvertices in two separate arrays.
2662 See also: ellipses2d, circleAsPolygon, rectAsPolygon, drawEllipse
2668 # name: <cell-element>
2672 Convert an ellipse into a series of points
2677 # name: <cell-element>
2684 # name: <cell-element>
2688 -- Function File: ellipses2d ()
2689 Description of functions operating on ellipses.
2691 Ellipses are represented by their center, the length of their 2
2692 semi-axes length, and their angle from the Ox direction (in
2693 degrees). E = [XC YC A B THETA];
2695 See also: circles2d, inertiaEllipse, isPointInEllipse,
2696 ellipseAsPolygon drawEllipse, drawEllipseArc
2702 # name: <cell-element>
2706 Description of functions operating on ellipses.
2710 # name: <cell-element>
2717 # name: <cell-element>
2721 -- Function File: CIRCLE = enclosingCircle (PTS)
2722 Find the minimum circle enclosing a set of points.
2724 CIRCLE = enclosingCircle(POINTS); compute cirlce CIRCLE=[xc yc
2725 r] which enclose all points POINTS given as an [Nx2] array.
2727 Rewritten from a file from Yazan Ahed which was
2728 rewritten from a Java applet by Shripad Thite :
2729 `http://heyoka.cs.uiuc.edu/~thite/mincircle/'
2731 See also: circles2d, points2d, boxes2d
2737 # name: <cell-element>
2741 Find the minimum circle enclosing a set of points.
2745 # name: <cell-element>
2749 fitAffineTransform2d
2752 # name: <cell-element>
2756 -- Function File: T = fitAffineTransform2d (PTS1, PTS2)
2757 Fit an affine transform using two point sets.
2762 pts = rand(N, 2)*10;
2763 trans = createRotation(3, 4, pi/4);
2764 pts2 = transformPoint(pts, trans);
2765 pts3 = pts2 + randn(N, 2)*2;
2766 fitted = fitAffineTransform2d(pts, pts2)
2768 See also: transforms2d
2774 # name: <cell-element>
2778 Fit an affine transform using two point sets.
2782 # name: <cell-element>
2789 # name: <cell-element>
2793 -- Function File: geom2d_Contents ()
2794 Geometry 2D Toolbox Version 1.2.0 21-Oct-2011 .
2796 Library to handle and visualize geometric primitives such as
2797 points, lines, circles and ellipses, polygons...
2799 The goal is to provide a low-level library for manipulating
2800 geometrical primitives, making easier the development of more
2801 complex geometric algorithms.
2803 Most functions works for planar shapes, but some ones have been
2804 extended to 3D or to any dimension.
2806 Points points2d - Description of functions operating
2807 on points clipPoints - Clip a set of points by a box
2808 centroid - Compute centroid (center of mass) of a set
2809 of points midPoint - Middle point of two points or
2810 of an edge isCounterClockwise - Compute relative orientation
2811 of 3 points polarPoint - Create a point from polar
2812 coordinates (rho + theta) angle2Points - Compute
2813 horizontal angle between 2 points angle3Points - Compute
2814 oriented angle made by 3 points angleSort - Sort
2815 points in the plane according to their angle to origin
2816 distancePoints - Compute distance between two points
2817 minDistancePoints - Minimal distance between several points
2818 transformPoint - Transform a point with an affine transform
2819 drawPoint - Draw the point on the axis.
2821 Vectors vectors2d - Description of functions
2822 operating on plane vectors createVector - Create a
2823 vector from two points vectorNorm - Compute norm of a
2824 vector, or of a set of vectors vectorAngle - Angle of a
2825 vector, or between 2 vectors normalizeVector - Normalize a
2826 vector to have norm equal to 1 isPerpendicular - Check
2827 orthogonality of two vectors isParallel - Check
2828 parallelism of two vectors transformVector - Transform a
2829 vector with an affine transform rotateVector - Rotate a
2830 vector by a given angle
2832 Straight lines lines2d - Description of functions
2833 operating on planar lines createLine - Create a
2834 straight line from 2 points, or from other inputs medianLine
2835 - Create a median line between two points cartesianLine
2836 - Create a straight line from cartesian equation coefficients
2837 orthogonalLine - Create a line orthogonal to another one.
2838 parallelLine - Create a line parallel to another one.
2839 intersectLines - Return all intersection points of N lines
2840 in 2D lineAngle - Computes angle between two straight
2841 lines linePosition - Position of a point on a line
2842 lineFit - Fit a straight line to a set of points
2843 clipLine - Clip a line with a box reverseLine
2844 - Return same line but with opposite orientation transformLine
2845 - Transform a line with an affine transform drawLine
2846 - Draw the line on the current axis
2848 Edges (line segments between 2 points) edges2d -
2849 Description of functions operating on planar edges createEdge
2850 - Create an edge between two points, or from a line
2851 edgeToLine - Convert an edge to a straight line
2852 edgeAngle - Return angle of edge edgeLength
2853 - Return length of an edge midPoint - Middle point
2854 of two points or of an edge edgePosition - Return
2855 position of a point on an edge clipEdge - Clip an
2856 edge with a rectangular box reverseEdge - Intervert the
2857 source and target vertices of edge intersectEdges - Return
2858 all intersections between two set of edges intersectLineEdge
2859 - Return intersection between a line and an edge transformEdge
2860 - Transform an edge with an affine transform drawEdge
2861 - Draw an edge given by 2 points drawCenteredEdge - Draw
2862 an edge centered on a point
2864 Rays rays2d - Description of functions operating
2865 on planar rays createRay - Create a ray (half-line),
2866 from various inputs bisector - Return the bisector
2867 of two lines, or 3 points clipRay - Clip a ray with
2868 a box drawRay - Draw a ray on the current axis
2870 Relations between points and lines distancePointEdge -
2871 Minimum distance between a point and an edge distancePointLine
2872 - Minimum distance between a point and a line projPointOnLine
2873 - Project of a point orthogonally onto a line pointOnLine
2874 - Create a point on a line at a given position on the line
2875 isPointOnLine - Test if a point belongs to a line
2876 isPointOnEdge - Test if a point belongs to an edge
2877 isPointOnRay - Test if a point belongs to a ray
2878 isLeftOriented - Test if a point is on the left side of a
2881 Circles circles2d - Description of functions
2882 operating on circles createCircle - Create a circle from
2883 2 or 3 points createDirectedCircle - Create a directed circle
2884 intersectCircles - Intersection points of two circles
2885 intersectLineCircle - Intersection point(s) of a line and a circle
2886 circleAsPolygon - Convert a circle into a series of points
2887 circleArcAsCurve - Convert a circle arc into a series of points
2888 isPointInCircle - Test if a point is located inside a given
2889 circle isPointOnCircle - Test if a point is located on a
2890 given circle. enclosingCircle - Find the minimum circle
2891 enclosing a set of points. radicalAxis - Compute the
2892 radical axis (or radical line) of 2 circles drawCircle
2893 - Draw a circle on the current axis drawCircleArc - Draw
2894 a circle arc on the current axis
2896 Ellipses ellipses2d - Description of functions
2897 operating on ellipses inertiaEllipse - Inertia ellipse of
2898 a set of points isPointInEllipse - Check if a point is
2899 located inside a given ellipse ellipseAsPolygon - Convert an
2900 ellipse into a series of points drawEllipse - Draw an
2901 ellipse on the current axis drawEllipseArc - Draw an
2902 ellipse arc on the current axis
2904 Geometric transforms transforms2d - Description of
2905 functions operating on transforms createTranslation - Create
2906 the 3*3 matrix of a translation createRotation - Create
2907 the 3*3 matrix of a rotation createScaling - Create the
2908 3*3 matrix of a scaling in 2 dimensions createHomothecy -
2909 Create the the 3x3 matrix of an homothetic transform
2910 createBasisTransform - Compute matrix for transforming a basis
2911 into another basis createLineReflection - Create the the 3x3
2912 matrix of a line reflection fitAffineTransform2d - Fit an affine
2913 transform using two point sets
2915 Angles angles2d - Description of functions for
2916 manipulating angles normalizeAngle - Normalize an angle
2917 value within a 2*PI interval angleAbsDiff - Absolute
2918 difference between two angles angleDiff - Difference
2919 between two angles deg2rad - Convert angle from
2920 degrees to radians rad2deg - Convert angle from
2923 Boxes boxes2d - Description of functions operating
2924 on bounding boxes intersectBoxes - Intersection of two
2925 bounding boxes mergeBoxes - Merge two boxes, by
2926 computing their greatest extent randomPointInBox - Generate
2927 random point within a box drawBox - Draw a box
2928 defined by coordinate extents
2930 Various drawing functions drawBezierCurve - Draw a cubic
2931 bezier curve defined by 4 control points drawParabola -
2932 Draw a parabola on the current axis drawOrientedBox - Draw
2933 centered oriented rectangle drawRect - Draw
2934 rectangle on the current axis drawArrow - Draw an
2935 arrow on the current axis drawLabels - Draw labels at
2936 specified positions drawShape - Draw various types of
2937 shapes (circles, polygons...)
2939 Other shapes squareGrid - Generate equally spaces
2940 points in plane. hexagonalGrid - Generate hexagonal grid
2941 of points in the plane. triangleGrid - Generate
2942 triangular grid of points in the plane. crackPattern -
2943 Create a (bounded) crack pattern tessellation crackPattern2
2944 - Create a (bounded) crack pattern tessellation
2946 Credits: * function 'enclosingCircle' rewritten from a file from
2947 Yazan Ahed , available on Matlab File Exchange
2953 # name: <cell-element>
2957 Geometry 2D Toolbox Version 1.
2961 # name: <cell-element>
2968 # name: <cell-element>
2972 -- Function File: PTS = hexagonalGrid (BOUNDS, ORIGIN, SIZE)
2973 Generate hexagonal grid of points in the plane.
2975 usage PTS = hexagonalGrid(BOUNDS, ORIGIN, SIZE) generate
2976 points, lying in the window defined by BOUNDS (=[xmin ymin xmax
2977 ymax]), starting from origin with a constant step equal to size.
2978 SIZE is constant and is equals to the length of the sides of each
2981 TODO: add possibility to use rotated grid
2986 # name: <cell-element>
2990 Generate hexagonal grid of points in the plane.
2994 # name: <cell-element>
3001 # name: <cell-element>
3005 -- Function File: ELL = inertiaEllipse (PTS)
3006 Inertia ellipse of a set of points
3008 ELL = inertiaEllipse(PTS); where PTS is a N*2 array containing
3009 coordinates of N points, computes the inertia ellispe of the set
3012 The result has the form: ELL = [XC YC A B THETA], with XC and
3013 YC being the center of mass of the point set, A and B are the
3014 lengths of the inertia ellipse (see below), and THETA is the angle
3015 of the main inertia axis with the horizontal (counted in degrees
3016 between 0 and 180). A and B are the standard deviations of the
3017 point coordinates when ellipse is aligned with the inertia axes.
3019 pts = randn(100, 2);
3020 pts = transformPoint(pts, createScaling(5, 2));
3021 pts = transformPoint(pts, createRotation(pi/6));
3022 pts = transformPoint(pts, createTranslation(3, 4));
3023 ell = inertiaEllipse(pts);
3024 figure(1); clf; hold on;
3026 drawEllipse(ell, 'linewidth', 2, 'color', 'r');
3028 See also: ellipses2d, drawEllipse
3034 # name: <cell-element>
3038 Inertia ellipse of a set of points
3043 # name: <cell-element>
3050 # name: <cell-element>
3054 -- Function File: BOX = intersectBoxes (BOX1, BOX2)
3055 Intersection of two bounding boxes.
3061 intersectBoxes(box1, box2)
3065 See also: boxes2d, drawBox, mergeBoxes
3071 # name: <cell-element>
3075 Intersection of two bounding boxes.
3079 # name: <cell-element>
3086 # name: <cell-element>
3090 -- Function File: POINTS = intersectCircles (CIRCLE1, CIRCLE2)
3091 Intersection points of two circles.
3093 POINTS = intersectCircles(CIRCLE1, CIRCLE2) Computes the
3094 intersetion point of the two circles CIRCLE1 and CIRCLE1. Both
3095 circles are given with format: [XC YC R], with (XC,YC) being the
3096 coordinates of the center and R being the radius. POINTS is a
3097 2-by-2 array, containing coordinate of an intersection point on
3098 each row. In the case of tangent circles, the intersection is
3099 returned twice. It can be simplified by using the 'unique'
3102 Example % intersection points of two distant circles c1 =
3103 [0 0 10]; c2 = [10 0 10]; pts = intersectCircles(c1, c2)
3104 pts = 5 -8.6603 5 8.6603
3106 % intersection points of two tangent circles c1 = [0 0 10];
3107 c2 = [20 0 10]; pts = intersectCircles(c1, c2) pts =
3108 10 0 10 0 pts2 = unique(pts, 'rows') pts2 =
3112 http://local.wasp.uwa.edu.au/~pbourke/geometry/2circle/
3113 http://mathworld.wolfram.com/Circle-CircleIntersection.html
3115 See also: circles2d, intersectLineCircle, radicalAxis
3121 # name: <cell-element>
3125 Intersection points of two circles.
3129 # name: <cell-element>
3136 # name: <cell-element>
3140 -- Function File: POINT = intersectEdges (EDGE1, EDGE2)
3141 Return all intersections between two set of edges
3143 P = intersectEdges(E1, E2); returns the intersection point of
3144 lines L1 and L2. E1 and E2 are 1-by-4 arrays, containing
3145 parametric representation of each edge (in the form [x1 y1 x2
3146 y2], see 'createEdge' for details).
3148 In case of colinear edges, returns [Inf Inf]. In case of
3149 parallel but not colinear edges, returns [NaN NaN].
3151 If each input is [N*4] array, the result is a [N*2] array
3152 containing intersections of each couple of edges. If one of
3153 the input has N rows and the other 1 row, the result is a [N*2]
3156 See also: edges2d, intersectLines
3162 # name: <cell-element>
3166 Return all intersections between two set of edges
3171 # name: <cell-element>
3178 # name: <cell-element>
3182 -- Function File: POINTS = intersectLineCircle (LINE, CIRCLE)
3183 Intersection point(s) of a line and a circle
3185 INTERS = intersectLineCircle(LINE, CIRCLE); Returns a 2-by-2
3186 array, containing on each row the coordinates of an intersection
3187 point. If the line and circle do not intersect, the result is
3190 Example % base point center = [10 0]; % create vertical line
3191 l1 = [center 0 1]; % circle c1 = [center 5]; pts =
3192 intersectLineCircle(l1, c1) pts = 10 -5 10 5
3193 % draw the result figure; clf; hold on; axis([0 20 -10 10]);
3194 drawLine(l1); drawCircle(c1); drawPoint(pts, 'rx'); axis
3197 See also: lines2d, circles2d, intersectLines, intersectCircles
3203 # name: <cell-element>
3207 Intersection point(s) of a line and a circle
3212 # name: <cell-element>
3219 # name: <cell-element>
3223 -- Function File: POINT = intersecLineEdge (LINE, EDGE)
3224 Return intersection between a line and an edge.
3226 Returns the intersection point of lines LINE and edge EDGE.
3227 LINE is a 1x4 array containing parametric representation of the
3228 line (in the form [x0 y0 dx dy], see `createLine' for details).
3229 EDGE is a 1x4 array containing coordinates of first and second
3230 point (in the form [x1 y1 x2 y2], see `createEdge' for details).
3232 In case of colinear line and edge, returns [Inf Inf]. If line
3233 does not intersect edge, returns [NaN NaN].
3235 If each input is [N*4] array, the result is a [N*2] array
3236 containing intersections for each couple of edge and line. If
3237 one of the input has N rows and the other 1 row, the result is a
3240 See also: lines2d, edges2d, intersectEdges, intersectLine
3246 # name: <cell-element>
3250 Return intersection between a line and an edge.
3254 # name: <cell-element>
3261 # name: <cell-element>
3265 -- Function File: POINT = intersectLines (LINE1, LINE2)
3266 -- Function File: POINT = intersectLines (LINE1, LINE2,EPS)
3267 Return all intersection points of N lines in 2D.
3269 Returns the intersection point of lines LINE1 and LINE2. LINE1
3270 and LINE2 are [1*4] arrays, containing parametric representation
3271 of each line (in the form [x0 y0 dx dy], see `createLine' for
3274 In case of colinear lines, returns [Inf Inf]. In case of
3275 parallel but not colinear lines, returns [NaN NaN].
3277 If each input is [N*4] array, the result is a [N*2] array
3278 containing intersections of each couple of lines. If one of
3279 the input has N rows and the other 1 row, the result is a [N*2]
3282 A third input argument specifies the tolerance for detecting
3283 parallel lines. Default is 1e-14.
3287 line1 = createLine([0 0], [10 10]);
3288 line2 = createLine([0 10], [10 0]);
3289 point = intersectLines(line1, line2)
3293 See also: lines2d, edges2d, intersectEdges, intersectLineEdge,
3300 # name: <cell-element>
3304 Return all intersection points of N lines in 2D.
3308 # name: <cell-element>
3315 # name: <cell-element>
3319 -- Function File: CCW = isCounterClockwise (P1, P2, P3)
3320 -- Function File: CCW = isCounterClockwise (P1, P2, P3,TOL)
3321 Compute relative orientation of 3 points
3323 Computes the orientation of the 3 points. The returns is: +1 if
3324 the path P1-> P2-> P3 turns Counter-Clockwise (i.e., the point P3
3325 is located "on the left" of the line P1- P2) -1 if the
3326 path turns Clockwise (i.e., the point P3 lies "on the right"
3327 of the line P1- P2) 0 if the point P3 is located on the line
3330 This function can be used in more complicated algorithms:
3331 detection of line segment intersections, convex hulls, point in
3334 CCW = isCounterClockwise( P1, P2, P3, EPS); Specifies the
3335 threshold used for detecting colinearity of the 3 points.
3336 Default value is 1e-12 (absolute).
3340 isCounterClockwise([0 0], [10 0], [10 10])
3343 isCounterClockwise([0 0], [0 10], [10 10])
3346 isCounterClockwise([0 0], [10 0], [5 0])
3350 See also: points2d, isPointOnLine, isPointInTriangle
3356 # name: <cell-element>
3360 Compute relative orientation of 3 points
3365 # name: <cell-element>
3372 # name: <cell-element>
3376 -- Function File: B = isLeftOriented (POINT, LINE)
3377 Test if a point is on the left side of a line
3379 B = isLeftOriented(POINT, LINE); Returns TRUE if the point lies
3380 on the left side of the line with respect to the line direction.
3382 See also: lines2d, points2d, isCounterClockwise, isPointOnLine,
3389 # name: <cell-element>
3393 Test if a point is on the left side of a line
3398 # name: <cell-element>
3405 # name: <cell-element>
3409 -- Function File: B = isParallel (V1, V2)
3410 -- Function File: B = isParallel (V1, V2,TOL)
3411 Check parallelism of two vectors
3413 V1 and V2 are 2 row vectors of length Nd, Nd being the dimension,
3414 returns `true' if the vectors are parallel, and `false' otherwise.
3416 Also works when V1 and V2 are two [NxNd] arrays with same number of
3417 rows. In this case, return a [Nx1] array containing `true' at the
3418 positions of parallel vectors.
3420 TOL specifies the accuracy of numerical computation. Default value
3425 isParallel([1 2], [2 4])
3428 isParallel([1 2], [1 3])
3432 See also: vectors2d, isPerpendicular, lines2d
3438 # name: <cell-element>
3442 Check parallelism of two vectors
3447 # name: <cell-element>
3454 # name: <cell-element>
3458 -- Function File: B = isPerpendicular (V1, V2)
3459 -- Function File: B = isPerpendicula (V1, V2,TOL)
3460 heck orthogonality of two vectors.
3462 V1 and V2 are 2 row vectors of length Nd, Nd being the dimension,
3463 returns `true' if the vectors are perpendicular, and `false'
3466 Also works when V1 and V2 are two [NxNd] arrays with same number of
3467 rows. In this case, return a [Nx1] array containing `true' at the
3468 positions of parallel vectors.
3470 TOL specifies the accuracy of numerical computation. Default value
3475 isPerpendicular([1 2 0], [0 0 2])
3478 isPerpendicular([1 2 1], [1 3 2])
3482 See also: vectors2d, isParallel, lines2d
3488 # name: <cell-element>
3492 heck orthogonality of two vectors.
3496 # name: <cell-element>
3503 # name: <cell-element>
3507 -- Function File: B = isPointInCircle (POINT, CIRCLE)
3508 Test if a point is located inside a given circle
3510 B = isPointInCircle(POINT, CIRCLE) Returns true if point is
3511 located inside the circle, i.e. if distance to circle center is
3512 lower than the circle radius.
3514 B = isPointInCircle(POINT, CIRCLE, TOL) Specifies the tolerance
3517 Example: isPointInCircle([1 0], [0 0 1]) isPointInCircle([0
3518 0], [0 0 1]) returns true, whereas isPointInCircle([1 1], [0 0
3521 See also: circles2d, isPointOnCircle
3527 # name: <cell-element>
3531 Test if a point is located inside a given circle
3536 # name: <cell-element>
3543 # name: <cell-element>
3547 -- Function File: B = isPointInellipse (POINT, ELLIPSE)
3548 Check if a point is located inside a given ellipse
3550 B = isPointInEllipse(POINT, ELLIPSE) Returns true if point is
3551 located inside the given ellipse.
3553 B = isPointInEllipse(POINT, ELLIPSE, TOL) Specifies the
3556 Example: isPointInEllipse([1 0], [0 0 2 1 0]) ans = 1
3557 isPointInEllipse([0 0], [0 0 2 1 0]) ans = 1
3558 isPointInEllipse([1 1], [0 0 2 1 0]) ans = 0
3559 isPointInEllipse([1 1], [0 0 2 1 30]) ans = 1
3561 See also: ellipses2d, isPointInCircle
3567 # name: <cell-element>
3571 Check if a point is located inside a given ellipse
3576 # name: <cell-element>
3583 # name: <cell-element>
3587 -- Function File: B = isPointOnCircle (POINT, CIRCLE)
3588 Test if a point is located on a given circle.
3590 B = isPointOnCircle(POINT, CIRCLE) return true if point is
3591 located on the circle, i.e. if the distance to the circle center
3592 equals the radius up to an epsilon value.
3594 B = isPointOnCircle(POINT, CIRCLE, TOL) Specifies the tolerance
3597 Example: isPointOnCircle([1 0], [0 0 1]) returns true, whereas
3598 isPointOnCircle([1 1], [0 0 1]) return false
3600 See also: circles2d, isPointInCircle
3606 # name: <cell-element>
3610 Test if a point is located on a given circle.
3614 # name: <cell-element>
3621 # name: <cell-element>
3625 -- Function File: B = isPointOnEdge (POINT, EDGE)
3626 -- Function File: B = isPointOnEdge (POINT, EDGE, TOL)
3627 -- Function File: B = isPointOnEdge (POINT, EDGEARRAY)
3628 -- Function File: B = isPointOnEdge (POINTARRAY, EDGEARRAY)
3629 Test if a point belongs to an edge.
3631 with POINT being [xp yp], and EDGE being [x1 y1 x2 y2], returns
3632 TRUE if the point is located on the edge, and FALSE otherwise.
3634 Specify an optilonal tolerance value TOL. The tolerance is given
3635 as a fraction of the norm of the edge direction vector. Default
3638 When one of the inputs has several rows, return the result of the
3639 test for each element of the array tested against the single
3642 When both POINTARRAY and EDGEARRAY have the same number of rows,
3643 returns a column vector with the same number of rows. When the
3644 number of rows are different and both greater than 1, returns a
3645 Np-by-Ne matrix of booleans, containing the result for each couple
3648 See also: edges2d, points2d, isPointOnLine
3654 # name: <cell-element>
3658 Test if a point belongs to an edge.
3662 # name: <cell-element>
3669 # name: <cell-element>
3673 -- Function File: B = isPointOnLine (POINT, LINE)
3674 Test if a point belongs to a line
3676 B = isPointOnLine(POINT, LINE) with POINT being [xp yp], and
3677 LINE being [x0 y0 dx dy]. Returns 1 if point lies on the line,
3680 If POINT is an N*2 array of points, B is a N*1 array of booleans.
3682 If LINE is a N*4 array of line, B is a 1*N array of booleans.
3684 See also: lines2d, points2d, isPointOnEdge, isPointOnRay,
3691 # name: <cell-element>
3695 Test if a point belongs to a line
3700 # name: <cell-element>
3707 # name: <cell-element>
3711 -- Function File: B = isPointOnRay (POINT, RAY)
3712 -- Function File: B = isPointOnRay (POINT, RAY, TOL)
3713 Test if a point belongs to a ray
3715 B = isPointOnRay(POINT, RAY); Returns `true' if point POINT
3716 belongs to the ray RAY. POINT is given by [x y] and RAY by [x0
3717 y0 dx dy]. TOL gives the tolerance for the calculations.
3719 See also: rays2d, points2d, isPointOnLine
3725 # name: <cell-element>
3729 Test if a point belongs to a ray
3734 # name: <cell-element>
3741 # name: <cell-element>
3745 -- Function File: THETA = lineAngle(varargin)
3746 Computes angle between two straight lines
3748 A = lineAngle(LINE); Returns the angle between horizontal,
3749 right-axis and the given line. Angle is fiven in radians,
3750 between 0 and 2*pi, in counter-clockwise direction.
3752 A = lineAngle(LINE1, LINE2); Returns the directed angle between
3753 the two lines. Angle is given in radians between 0 and 2*pi, in
3754 counter-clockwise direction.
3756 See also: lines2d, angles2d, createLine, normalizeAngle
3762 # name: <cell-element>
3766 Computes angle between two straight lines
3771 # name: <cell-element>
3778 # name: <cell-element>
3782 -- Function File: POS = linePosition (POINT, LINE)
3783 Position of a point on a line.
3785 Computes position of point POINT on the line LINE, relative to
3786 origin point and direction vector of the line. LINE has the
3787 form [x0 y0 dx dy], POINT has the form [x y], and is assumed to
3790 If LINE is an array of NL lines, return NL positions,
3791 corresponding to each line.
3793 If POINT is an array of NP points, return NP positions,
3794 corresponding to each point.
3796 If POINT is an array of NP points and LINES is an array of NL
3797 lines, return an array of [NP NL] position, corresponding to
3798 each couple point-line.
3802 line = createLine([10 30], [30 90]);
3803 linePosition([20 60], line)
3807 See also: lines2d, createLine, projPointOnLine, isPointOnLine
3813 # name: <cell-element>
3817 Position of a point on a line.
3821 # name: <cell-element>
3828 # name: <cell-element>
3832 -- Function File: lines2d ()
3833 Description of functions operating on planar lines.
3835 The term 'line' refers to a planar straight line, which is an
3836 unbounded curve. Line segments defined between 2 points, which
3837 are bounded, are called 'edge', and are presented in file
3840 A straight line is defined by a point (its origin), and a vector
3841 (its direction). The different parameters are bundled into a row
3842 vector: LINE = [x0 y0 dx dy];
3844 A line contains all points (x,y) such that: x = x0 + t*dx
3845 y = y0 + t*dy; for all t between -infinity and +infinity.
3847 See also: points2d, vectors2d, edges2d, rays2d createLine,
3848 cartesianLine, medianLine, edgeToLine orthogonalLine,
3849 parallelLine, bisector, radicalAxis lineAngle, linePosition,
3850 projPointOnLine isPointOnLine, distancePointLine, isLeftOriented
3851 intersectLines, intersectLineEdge, clipLine invertLine,
3852 transformLine, drawLine lineFit
3858 # name: <cell-element>
3862 Description of functions operating on planar lines.
3866 # name: <cell-element>
3873 # name: <cell-element>
3877 -- Function File: LINE = medianLine (P1, P2)
3878 -- Function File: LINE = medianLine (PTS)
3879 -- Function File: LINE = medianLine (EDGE)
3880 Create a median line between two points.
3882 Create the median line of points P1 and P2, that is the line
3883 containing all points located at equal distance of P1 and P2.
3885 Creates the median line of 2 points, given as a 2*2 array PTS.
3886 Array has the form: [ [ x1 y1 ] ; [ x2 y2 ] ]
3888 Creates the median of the EDGE. EDGE is a 1*4 array, containing
3889 [X1 Y1] coordinates of first point, and [X2 Y2], the coordinates
3890 of the second point.
3894 % Draw the median line of two points
3897 med = medianLine(P1, P2);
3898 figure; axis square; axis([0 100 0 100]);
3899 drawEdge([P1 P2], 'linewidth', 2, 'color', 'k');
3902 % Draw the median line of an edge
3905 edge = createEdge(P1, P2);
3906 figure; axis square; axis([0 100 0 100]);
3907 drawEdge(edge, 'linewidth', 2)
3908 med = medianLine(edge);
3911 See also: lines2d, createLine, orthogonalLine
3917 # name: <cell-element>
3921 Create a median line between two points.
3925 # name: <cell-element>
3932 # name: <cell-element>
3936 -- Function File: BOX = mergeBoxes (BOX1, BOX2)
3937 Merge two boxes, by computing their greatest extent.
3943 mergeBoxes(box1, box2)
3947 See also: boxes2d, drawBox, intersectBoxes
3953 # name: <cell-element>
3957 Merge two boxes, by computing their greatest extent.
3961 # name: <cell-element>
3968 # name: <cell-element>
3972 -- Function File: MID = midPoint (P1, P2)
3973 -- Function File: MID = midPoint (EDGE)
3974 -- Function File: [MIDX, MIDY] = midPoint (EDGE)
3975 Middle point of two points or of an edge
3977 Computes the middle point of the two points P1 and P2.
3979 If an edge is given, computes the middle point of the edge given
3980 by EDGE. EDGE has the format: [X1 Y1 X2 Y2], and MID has the
3981 format [XMID YMID], with XMID = (X1+X2)/2, and YMID = (Y1+Y2)/2.
3983 If two output arguments are given, it returns the result as two
3984 separate variables or arrays.
3986 Works also when EDGE is a N-by-4 array, in this case the result is
3987 a N-by-2 array containing the midpoint of each edge.
3997 See also: edges2d, points2d
4003 # name: <cell-element>
4007 Middle point of two points or of an edge
4012 # name: <cell-element>
4019 # name: <cell-element>
4023 -- Function File: DIST = minDistancePoints (PTS)
4024 -- Function File: DIST = minDistancePoints (PTS1,PTS2)
4025 -- Function File: DIST = minDistancePoints (...,NORM)
4026 -- Function File: [DIST I J] = minDistancePoints (PTS1, PTS2, ...)
4027 -- Function File: [DIST J] = minDistancePoints (PTS1, PTS2, ...)
4028 Minimal distance between several points.
4030 Returns the minimum distance between all couple of points in PTS.
4031 PTS is an array of [NxND] values, N being the number of points
4032 and ND the dimension of the points.
4034 Computes for each point in PTS1 the minimal distance to every
4035 point of PTS2. PTS1 and PTS2 are [NxD] arrays, where N is the
4036 number of points, and D is the dimension. Dimension must be the
4037 same for both arrays, but number of points can be different.
4038 The result is an array the same length as PTS1.
4040 When NORM is provided, it uses a user-specified norm. NORM=2 means
4041 euclidean norm (the default), NORM=1 is the Manhattan (or
4042 "taxi-driver") distance. Increasing NORM growing up reduces the
4043 minimal distance, with a limit to the biggest coordinate
4044 difference among dimensions.
4046 Returns indices I and J of the 2 points which are the closest. DIST
4047 verifies relation: DIST = distancePoints(PTS(I,:), PTS(J,:));
4049 If only 2 output arguments are given, it returns the indices of
4050 points which are the closest. J has the same size as DIST. for
4051 each I It verifies the relation : DIST(I) =
4052 distancePoints(PTS1(I,:), PTS2(J,:));
4056 % minimal distance between random planar points
4057 points = rand(20,2)*100;
4058 minDist = minDistancePoints(points);
4060 % minimal distance between random space points
4061 points = rand(30,3)*100;
4062 [minDist ind1 ind2] = minDistancePoints(points);
4064 distancePoints(points(ind1, :), points(ind2, :))
4065 % results should be the same
4067 % minimal distance between 2 sets of points
4068 points1 = rand(30,2)*100;
4069 points2 = rand(30,2)*100;
4070 [minDists inds] = minDistancePoints(points1, points2);
4072 distancePoints(points1(10, :), points2(inds(10), :))
4073 % results should be the same
4075 See also: points2d, distancePoints
4081 # name: <cell-element>
4085 Minimal distance between several points.
4089 # name: <cell-element>
4096 # name: <cell-element>
4100 -- Function File: ALPHA2 = normalizeAngle (ALPHA)
4101 -- Function File: ALPHA2 = normalizeAngle (ALPHA, CENTER)
4102 Normalize an angle value within a 2*PI interval
4104 ALPHA2 = normalizeAngle(ALPHA); ALPHA2 is the same as ALPHA
4105 modulo 2*PI and is positive.
4107 ALPHA2 = normalizeAngle(ALPHA, CENTER); Specifies the center of
4108 the angle interval. If CENTER==0, the interval is [-pi ; +pi]
4109 If CENTER==PI, the interval is [0 ; 2*pi] (default).
4111 Example: % normalization between 0 and 2*pi (default)
4112 normalizeAngle(5*pi) ans = 3.1416
4114 % normalization between -pi and +pi normalizeAngle(7*pi/2, 0)
4117 References Follows the same convention as apache commons
4119 http://commons.apache.org/math/api-2.2/org/apache/commons/math/util/MathUtils.html%%
4121 See also: vectorAngle, lineAngle
4127 # name: <cell-element>
4131 Normalize an angle value within a 2*PI interval
4136 # name: <cell-element>
4143 # name: <cell-element>
4147 -- Function File: VN = normalizeVector (V)
4148 Normalize a vector to have norm equal to 1
4150 Returns the normalization of vector V, such that ||V|| = 1. V can
4151 be either a row or a column vector.
4153 When V is a MxN array, normalization is performed for each row of
4158 vn = normalizeVector([3 4])
4165 See also: vectors2d, vectorNorm
4171 # name: <cell-element>
4175 Normalize a vector to have norm equal to 1
4180 # name: <cell-element>
4187 # name: <cell-element>
4191 -- Function File: PERP = orthogonalLine (LINE, POINT)
4192 Create a line orthogonal to another one.
4194 Returns the line orthogonal to the line LINE and going through the
4195 point given by POINT. Directed angle from LINE to PERP is pi/2.
4196 LINE is given as [x0 y0 dx dy] and POINT is [xp yp].
4198 See also: lines2d, parallelLine
4204 # name: <cell-element>
4208 Create a line orthogonal to another one.
4212 # name: <cell-element>
4219 # name: <cell-element>
4223 -- Function File: RES = parallelLine (LINE, POINT)
4224 -- Function File: RES = parallelLine (LINE, DIST)
4225 Create a line parallel to another one.
4227 Returns the line with same direction vector than LINE and going
4228 through the point given by POINT. LINE is given as [x0 y0 dx
4229 dy] and POINT is [xp yp].
4231 Uses relative distance to specify position. The new line will be
4232 located at distance DIST, counted positive in the right side of
4233 LINE and negative in the left side.
4235 See also: lines2d, orthogonalLine, distancePointLine
4241 # name: <cell-element>
4245 Create a line parallel to another one.
4249 # name: <cell-element>
4256 # name: <cell-element>
4260 -- Function File: POINT = pointOnLine (LINE, D)
4261 Create a point on a line at a given position on the line.
4263 Creates the point belonging to the line LINE, and located at the
4264 distance D from the line origin. LINE has the form [x0 y0 dx
4265 dy]. LINE and D should have the same number N of rows. The
4266 result will have N rows and 2 column (x and y positions).
4268 See also: lines2d, points2d, onLine, onLine, linePosition
4274 # name: <cell-element>
4278 Create a point on a line at a given position on the line.
4282 # name: <cell-element>
4289 # name: <cell-element>
4293 -- Function File: points2d ()
4294 Description of functions operating on points.
4296 A point is defined by its two cartesian coordinate, put into a row
4297 vector of 2 elements: P = [x y];
4299 Several points are stores in a matrix with two columns, one for the
4300 x-coordinate, one for the y-coordinate. PTS = [x1 y1 ; x2 y2 ;
4305 See also: centroid, midPoint, polarPoint, pointOnLine
4306 isCounterClockwise, angle2Points, angle3Points, angleSort
4307 distancePoints, minDistancePoints transformPoint, clipPoints,
4314 # name: <cell-element>
4318 Description of functions operating on points.
4322 # name: <cell-element>
4329 # name: <cell-element>
4333 -- Function File: POINT = polarPoint (RHO, THETA)
4334 -- Function File: POINT = polarPoint (THETA)
4335 -- Function File: POINT = polarPoint (POINT, RHO, THETA)
4336 -- Function File: POINT = polarPoint (X0, Y0, RHO, THETA)
4337 Create a point from polar coordinates (rho + theta)
4339 Creates a point using polar coordinate. THETA is angle with
4340 horizontal (counted counter-clockwise, and in radians), and RHO
4341 is the distance to origin. If only angle is given radius RHO is
4344 If a point is given, adds the coordinate of the point to the
4345 coordinate of the specified point. For example, creating a point
4346 with : P = polarPoint([10 20], 30, pi/2); will give a result
4355 # name: <cell-element>
4359 Create a point from polar coordinates (rho + theta)
4364 # name: <cell-element>
4371 # name: <cell-element>
4375 -- Function File: POINT = projPointOnLine (PT1, LINE)
4376 Project of a point orthogonally onto a line
4378 Computes the (orthogonal) projection of point PT1 onto the line
4381 Function works also for multiple points and lines. In this case, it
4382 returns multiple points. Point PT1 is a [N*2] array, and LINE
4383 is a [N*4] array (see createLine for details). Result POINT is a
4384 [N*2] array, containing coordinates of orthogonal projections of
4385 PT1 onto lines LINE.
4387 See also: lines2d, points2d, isPointOnLine, linePosition
4393 # name: <cell-element>
4397 Project of a point orthogonally onto a line
4402 # name: <cell-element>
4409 # name: <cell-element>
4413 -- Function File: DEG = rad2deg(RAD)
4414 Convert angle from radians to degrees
4416 Usage: R = rad2deg(D) convert an angle in radians to angle in
4419 Example: rad2deg(pi) ans = 180 rad2deg(pi/3) ans =
4422 See also: angles2d, deg2rad
4428 # name: <cell-element>
4432 Convert angle from radians to degrees
4437 # name: <cell-element>
4444 # name: <cell-element>
4448 -- Function File: LINE = radicalAxis (CIRCLE1, CIRCLE2)
4449 Compute the radical axis (or radical line) of 2 circles
4451 L = radicalAxis(C1, C2) Computes the radical axis of 2 circles.
4453 Example C1 = [10 10 5]; C2 = [60 50 30]; L = radicalAxis(C1,
4454 C2); hold on; axis equal;axis([0 100 0 100]);
4455 drawCircle(C1);drawCircle(C2);drawLine(L);
4457 Ref: http://mathworld.wolfram.com/RadicalLine.html
4458 http://en.wikipedia.org/wiki/Radical_axis
4460 See also: lines2d, circles2d, createCircle
4466 # name: <cell-element>
4470 Compute the radical axis (or radical line) of 2 circles
4475 # name: <cell-element>
4482 # name: <cell-element>
4486 -- Function File: POINTS = randomPointInBox (BOX)
4487 -- Function File: POINTS = randomPointInBox (BOX, N)
4488 Generate random points within a box.
4490 Generate a random point within the box BOX. The result is a 1-by-2
4491 row vector. If N is given, generates N points. The result is a
4496 % draw points within a box
4497 box = [10 80 20 60];
4498 pts = randomPointInBox(box, 500);
4499 figure(1); clf; hold on;
4501 drawPoint(pts, '.');
4503 axis([0 100 0 100]);
4505 See also: edges2d, boxes2d, clipLine
4511 # name: <cell-element>
4515 Generate random points within a box.
4519 # name: <cell-element>
4526 # name: <cell-element>
4530 -- Function File: rays2d ()
4531 Description of functions operating on planar rays
4533 A ray is defined by a point (its origin), and a vector (its
4534 direction). The different parameters are bundled into a row vector:
4535 `RAY = [x0 y0 dx dy];'
4537 The ray contains all the points (x,y) such that: x = x0 + t*dx
4538 y = y0 + t*dy; for all t>0
4540 Contrary to a (straight) line, the points located before the
4541 origin do not belong to the ray. However, as rays and lines
4542 have the same representation, some functions working on lines
4543 are also working on rays (like `transformLine').
4545 See also: points2d, vectors2d, lines2d, createRay, bisector,
4546 isPointOnRay, clipRay, drawRay
4552 # name: <cell-element>
4556 Description of functions operating on planar rays
4561 # name: <cell-element>
4568 # name: <cell-element>
4572 -- Function File: RES = reverseEdge (EDGE)
4573 Intervert the source and target vertices of edge
4575 REV = reverseEdge(EDGE); Returns the opposite edge of EDGE.
4576 EDGE has the format [X1 Y1 X2 Y2]. The resulting edge REV has value
4579 See also: edges2d, createEdge, reverseLine
4585 # name: <cell-element>
4589 Intervert the source and target vertices of edge
4594 # name: <cell-element>
4601 # name: <cell-element>
4605 -- Function File: LINE = reverseLine (LINE)
4606 Return same line but with opposite orientation
4608 INVLINE = reverseLine(LINE); Returns the opposite line of LINE.
4609 LINE has the format [x0 y0 dx dy], then INVLINE will have
4610 following parameters: [x0 y0 -dx -dy].
4612 See also: lines2d, createLine
4618 # name: <cell-element>
4622 Return same line but with opposite orientation
4627 # name: <cell-element>
4634 # name: <cell-element>
4638 -- Function File: VR = rotateVector (V, THETA)
4639 Rotate a vector by a given angle
4641 Rotate the vector V by an angle THETA, given in radians.
4645 rotateVector([1 0], pi/2)
4649 See also: vectors2d, transformVector, createRotation
4655 # name: <cell-element>
4659 Rotate a vector by a given angle
4664 # name: <cell-element>
4671 # name: <cell-element>
4675 -- Function File: PTS = squaregrid (BOUNDS, ORIGIN, SIZE)
4676 Generate equally spaces points in plane.
4678 usage PTS = squareGrid(BOUNDS, ORIGIN, SIZE) generate points,
4679 lying in the window defined by BOUNDS (=[xmin ymin xmax ymax]),
4680 starting from origin with a constant step equal to size.
4682 Example PTS = squareGrid([0 0 10 10], [3 3], [4 2]) will
4683 return points : [3 1;7 1;3 3;7 3;3 5;7 5;3 7;7 7;3 9;7 9];
4685 TODO: add possibility to use rotated grid
4691 # name: <cell-element>
4695 Generate equally spaces points in plane.
4699 # name: <cell-element>
4706 # name: <cell-element>
4710 -- Function File: EDGE2 = transformEdge (EDGE1, T)
4711 Transform an edge with an affine transform.
4713 Where EDGE1 has the form [x1 y1 x2 y1], and T is a transformation
4714 matrix, return the edge transformed with affine transform T.
4716 Format of TRANS can be one of : [a b] , [a b c] , or [a b c]
4717 [d e] [d e f] [d e f] [0 0
4720 Also works when EDGE1 is a [Nx4] array of double. In this case,
4721 EDGE2 has the same size as EDGE1.
4723 See also: edges2d, transforms2d, transformPoint, translation,
4730 # name: <cell-element>
4734 Transform an edge with an affine transform.
4738 # name: <cell-element>
4745 # name: <cell-element>
4749 -- Function File: LINE2 = transformLine (LINE1, T)
4750 Transform a line with an affine transform.
4752 Returns the line LINE1 transformed with affine transform T.
4753 LINE1 has the form [x0 y0 dx dy], and T is a transformation
4756 Format of T can be one of : [a b] , [a b c] , or [a b c]
4757 [d e] [d e f] [d e f] [0 0 1]
4759 Also works when LINE1 is a [Nx4] array of double. In this case,
4760 LINE2 has the same size as LINE1.
4762 See also: lines2d, transforms2d, transformPoint
4768 # name: <cell-element>
4772 Transform a line with an affine transform.
4776 # name: <cell-element>
4783 # name: <cell-element>
4787 -- Function File: PT2 = transformPoint (PT1, TRANS)
4788 -- Function File: [PX2 PY2]= transformPoint (PX1, PY1, TRANS)
4789 Transform a point with an affine transform.
4791 where PT1 has the form [xp yp], and TRANS is a [2x2], [2x3] or
4792 [3x3] matrix, returns the point transformed with affine
4795 Format of TRANS can be one of : [a b] , [a b c] , or [a b c]
4796 [d e] [d e f] [d e f] [0 0
4799 Also works when PT1 is a [Nx2] array of double. In this case, PT2
4800 has the same size as PT1.
4802 Also works when PX1 and PY1 are arrays the same size. The function
4803 transform each couple of (PX1, PY1), and return the result in
4804 (PX2, PY2), which is the same size as (PX1 PY1).
4806 See also: points2d, transforms2d, createTranslation, createRotation
4812 # name: <cell-element>
4816 Transform a point with an affine transform.
4820 # name: <cell-element>
4827 # name: <cell-element>
4831 -- Function File: V2 = transformVector (V, T)
4832 -- Function File: [X2 Y2] = transformVector (X,Y, T)
4833 Transform a vector with an affine transform
4835 V has the form [xv yv], and T is a [2x2], [2x3] or [3x3] matrix,
4836 returns the vector transformed with affine transform T.
4838 Format of T can be one of :
4839 [a b] , [a b c] , or [a b c] [d e] [d e f] [d e f]
4842 Also works when V is a [Nx2] array of double. In this case, V2 has
4845 Also works when X and Y are arrays the same size. The function
4846 transform each couple of (X, Y), and return the result in (X2,
4847 Y2), which is the same size as (X, Y).
4849 See also: vectors2d, transforms2d, rotateVector, transformPoint
4855 # name: <cell-element>
4859 Transform a vector with an affine transform
4864 # name: <cell-element>
4871 # name: <cell-element>
4875 -- Function File: transforms2d ()
4876 Description of functions operating on transforms
4878 By 'transform' we mean an affine transform. A planar affine
4879 transform can be represented by a 3x3 matrix.
4883 % create a translation by the vector [10 20]:
4884 T = createTranslation([10 20])
4890 See also: createTranslation, createRotation, createScaling,
4891 createBasisTransform, createHomothecy, createLineReflection,
4892 fitAffineTransform2d, transformPoint, transformVector,
4893 transformLine, transformEdge, rotateVector
4899 # name: <cell-element>
4903 Description of functions operating on transforms
4908 # name: <cell-element>
4915 # name: <cell-element>
4919 -- Function File: PTS = triangleGrid (BOUNDS, ORIGIN, SIZE)
4920 Generate triangular grid of points in the plane.
4922 usage PTS = triangleGrid(BOUNDS, ORIGIN, SIZE) generate
4923 points, lying in the window defined by BOUNDS, given in form
4924 [xmin ymin xmax ymax], starting from origin with a constant step
4925 equal to size. SIZE is constant and is equals to the length
4926 of the sides of each triangles.
4928 TODO: add possibility to use rotated grid
4934 # name: <cell-element>
4938 Generate triangular grid of points in the plane.
4942 # name: <cell-element>
4949 # name: <cell-element>
4953 -- Function File: ALPHA = vectorAngle (V1)
4954 Angle of a vector, or between 2 vectors
4956 A = vectorAngle(V); Returns angle between Ox axis and vector
4957 direction, in Counter clockwise orientation. The result is
4958 normalised between 0 and 2*PI.
4960 A = vectorAngle(V1, V2); Returns the angle from vector V1 to
4961 vector V2, in counter-clockwise order, and in radians.
4963 A = vectorAngle(..., 'cutAngle', CUTANGLE); A = vectorAngle(...,
4964 CUTANGLE); % (deprecated syntax) Specifies convention for angle
4965 interval. CUTANGLE is the center of the 2*PI interval containing
4966 the result. See <a href="matlab:doc
4967 ('normalizeAngle')">normalizeAngle</a> for details.
4969 Example: rad2deg(vectorAngle([2 2])) ans = 45
4970 rad2deg(vectorAngle([1 sqrt(3)])) ans = 60
4971 rad2deg(vectorAngle([0 -1])) ans = 270
4973 See also: vectors2d, angles2d, normalizeAngle
4979 # name: <cell-element>
4983 Angle of a vector, or between 2 vectors
4988 # name: <cell-element>
4995 # name: <cell-element>
4999 -- Function File: NM = vectorNorm (V)
5000 -- Function File: NM = vectorNorm (V,N)
5001 Compute norm of a vector, or of a set of vectors
5003 Without extra arguments, returns the euclidean norm of vector V.
5004 Optional argument N specifies the norm to use. N can be any value
5015 When V is a MxN array, compute norm for each vector of the array.
5016 Vector are given as rows. Result is then a Mx1 array.
5020 n1 = vectorNorm([3 4])
5024 n2 = vectorNorm([1, 10], inf)
5028 See also: vectors2d, vectorAngle
5034 # name: <cell-element>
5038 Compute norm of a vector, or of a set of vectors
5043 # name: <cell-element>
5050 # name: <cell-element>
5054 -- Function File: vectors2d ()
5055 Description of functions operating on plane vectors
5057 A vector is defined by its two cartesian coordinates, put into a
5058 row vector of 2 elements: `V = [vx vy];'
5060 Several vectors are stored in a matrix with two columns, one for
5061 the x-coordinate, one for the y-coordinate. `VS = [vx1 vy1 ;
5062 vx2 vy2 ; vx3 vy3];'
5064 See also: vectorNorm, vectorAngle, isPerpendicular, isParallel,
5065 normalizeVector, transformVector, rotateVector
5071 # name: <cell-element>
5075 Description of functions operating on plane vectors