Finding coordinates x,y,z of circle center point.
Hello.
Could someone have a code in RAPID for finding coordinates x,y,z of a circle center created from 3 points A,B,C in wobj0.
0
Comments
-
Hi!
If you still have trouble with this you can try the following code. Circle3P function computes circle center, axis and radius for the given three perimeter points p1, p2 and p3. I tested this a bit and it seemed to work fine. Note that this only works on new RobotWare because it uses MatrixSolve function.
BR, Keke
MODULE MainModule<br> <br> CONST num nEPSILON:=1e-6;<br> <br> PROC main()<br> VAR pos p1;<br> VAR pos p2;<br> VAR pos p3;<br> VAR pos c;<br> VAR pos a;<br> VAR num r;<br> VAR bool b;<br> !<br> p1:=[200,0,100];<br> p2:=[0,0,100];<br> p3:=[0,200,100];<br> b:=Circle3P(p1,p2,p3,c,a,r);<br> !<br> Stop;<br> ENDPROC<br> <br> FUNC num Max(num n1, num n2)<br> !--------------------------------<br> !Return maximum of two numbers<br> !--------------------------------<br> !<br> IF n1 > n2 THEN<br> RETURN n1;<br> ELSE<br> RETURN n2;<br> ENDIF<br> ENDFUNC<br> <br> FUNC num PosLength(pos p)<br> !--------------------------------<br> !Length of a vector (pos)<br> !--------------------------------<br> !<br> VAR num nL;<br> nL:=sqrt(Max(0,p.x*p.x+p.y*p.y+p.z*p.z));<br> RETURN nL;<br> ENDFUNC<br> <br> FUNC pos CrossProd(pos p1,pos p2)<br> !--------------------------------<br> !Calculate cross product for vectors p1 and p2.<br> !--------------------------------<br> !<br> VAR pos px;<br> px:=[0,0,0];<br> px.x:=p1.y*p2.z-p2.y*p1.z;<br> px.y:=p2.x*p1.z-p1.x*p2.z;<br> px.z:=p1.x*p2.y-p2.x*p1.y;<br> RETURN px;<br> ENDFUNC<br> <br> FUNC bool Circle3P(pos p1,pos p2,pos p3,INOUT pos center,INOUT pos axis,INOUT num radius)<br> !--------------------------------<br> !Calculate center point, axis and radius for a circle formed by <br> !three point p1, p2 and p3. Axis is unit vector.<br> !Returns True if found, False if points are on a on a single line (infinite radius).<br> !--------------------------------<br> !<br> VAR pos v12;<br> VAR pos v23;<br> VAR pos px;<br> VAR pos p12mid;<br> VAR pos p23mid;<br> VAR pos n12;<br> VAR pos n23;<br> VAR pos diff;<br> VAR num l;<br> VAR dnum A{3,3};<br> VAR dnum b{3};<br> VAR dnum x{3};<br> !<br> center:=[0,0,0];<br> axis:=[0,0,0];<br> radius:=0;<br> !<br> v12:=p2-p1;<br> v23:=p3-p2;<br> px:=CrossProd(v12,v23);<br> l:=PosLength(px);<br> IF l<nEPSILON THEN<br> RETURN FALSE;<br> ENDIF<br> px:=(1.0/l)*px;<br> axis:=px;<br> !<br> p12mid:=p1+0.5*v12;<br> p23mid:=p2+0.5*v23;<br> n12:=CrossProd(v12,axis);<br> n23:=CrossProd(v23,axis);<br> !<br> A:=[[NumToDnum(v12.x),NumToDnum(v12.y),NumToDnum(v12.z)],<br> [NumToDnum(v23.x),NumToDnum(v23.y),NumToDnum(v23.z)],<br> [NumToDnum(axis.x),NumToDnum(axis.y),NumToDnum(axis.z)]];<br> b:=[NumToDnum(DotProd(v12,p12mid)),NumToDnum(DotProd(v23,p23mid)),NumToDnum(DotProd(axis,p2))];<br> MatrixSolve A,b,x;<br> !<br> center:=[DnumToNum(x{1}),DnumToNum(x{2}),DnumToNum(x{3})];<br> diff:=center-p1;<br> radius:=PosLength(diff);<br> !<br> RETURN TRUE;<br> ENDFUNC<br>ENDMODULE
0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 799 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings