Lsqumeth
Gets the approximate line from multiple point coordinates using the method of least squares.
Lsqumeth <No. of Coordinates>,<X Coordinate>,<Y Coordinate>,<Straight Line Component>
Parameters
<No. of Coordinates>
|
The number of coordinates that will be calculated for the approximate line (integer).
|
<X Coordinate>
|
X coordinate array of the point for calculating the approximate line (double-precision array).
|
<Y Coordinate>
|
Y coordinate array of the point for calculating the approximate line (double-precision array).
|
<Straight Line Component>
|
Approximate straight line parameter (double-precision array).
|
Return Value
None.
Description
Specify the array to store the point of each coordinate in the <X Coordinate> and <Y Coordinate>.When the specified <Number of Coordinates> is less than the number of array elements, an error will occur.
The parameters a, b and c that make up the straight line ax+by+c=0 are stored in <Straight Line Component>."a" to "c" are each stored in array elements 0 to 2.
It is necessary to specify a number greater than or equal to 2 for <Number of Coordinates>.
When all of the specified points are the same coordinate, 0 is stored in the a, b and c listed above.
This is mainly used to get the straight line expression of an edge from the edge points measured by multiple Edge measurements.
Example
Calculate the line expression of an edge on a piece of work from 4 edge points.Render the straight line gotten in the graphics screen.
Dim POSX#(3),POSY#(3),PARM#(2)
For I&=0 To 3
GetUnitData I&+1,"X",POSX#(I&)
GetUnitData I&+1,"Y",POSY#(I&)
Next
Lsqumeth 4,POSX#(),POSY#(),PARM#()
If PARM#(0)=0 Then
DrawLine 0,-PARM#(2)/PARM#(1),511,-PARM#(2)/PARM#(1),0,5
Elseif PARM#(1)=0 Then
DrawLine -PARM#(2)/PARM#(0),0,-PARM#(2)/PARM#(0),400,0,5
Elseif PARM#(1)/PARM#(0)>0 Then
DrawLine 0,-PARM#(2)/PARM#(1),-PARM#(2)/PARM#(0),0,0,5
Else
DrawLine 0,-PARM#(2)/PARM#(1),511,-(PARM#(2)+PARM#(0)*511)/PARM#(1),0,5
EndIf
Erase POSX#(),POSY#(),PARM#()