0% found this document useful (0 votes)
30 views28 pages

Presentation - COMPUTATIONAL GEOMETRY FOR MACHINING

The document discusses computational geometry concepts for machining including lines, line segments, circles, tangents, normals, and vector products. It also discusses the MAPT language for computational geometry including its grammar, data structures, parsing, and processing to output APT or MAPT CL data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views28 pages

Presentation - COMPUTATIONAL GEOMETRY FOR MACHINING

The document discusses computational geometry concepts for machining including lines, line segments, circles, tangents, normals, and vector products. It also discusses the MAPT language for computational geometry including its grammar, data structures, parsing, and processing to output APT or MAPT CL data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

©T.C.

Chang

COMPUTATIONAL GEOMETRY
FOR MACHINING

and

MAPT LANGUAGE DEVELOPMENT

04/19/20 10 - 1
©T.C. Chang

BASIC COMPUTATIONAL GEOMETRY


Line:
y= b x + c y = (f x) explicit equation x = x(t)
parametric form
y = y( t)
( x2 – x1) ( y– 1y) = ( 2y – 1y) ( x– x1 ) (f x, y) = 0 implicit equation

Line segment passing ( x1, 1y) & ( x2, 2y)

x = x1 + ( x2 – x1)t
0   t  1
y = 1y + ( 2y – 1y)t

Circle: x = cos t
0 t2
y = r 2 – x2 x2 + y2 – r 2 = 0 y = sin t

Tangent:
d (f x1)
y = 1y + ( x – x1 )
dx
Normal:
y = 1y – ( x – x1 ) 1 d f( x1)
dx

Two lines: a1 x + b1 y+ c1 = 0 & a2 x + b2 y+ c2 = 0

a1 b2 = a2 b1 parallel to each other


a1 a2 + b1 b2 = 0 perpendicular to each other

04/19/20 10 - 2
©T.C. Chang

TANGENT AND
NORMAL
Tangent of a parametric curve:
x = x(t)  0t 1
Curve: y = y( t)
0   t  1 or r(t)

Tangent vector: T = ( x, y)
x = dx(t) dt
y = dy(t) dt
N
Tangent line T
x = x(t) +  x(t) r(t1)
–    
y = y( t) +  y( t)

Normal vector: N = ( – y, x) r(t)

Uni-normal vector:

U = N N = x2 + y2
N

04/19/20 10 - 3
©T.C. Chang

CUTTER OFFSET
N
T Cutter diameter = d

Cutter tip locates at r(t1) . It is also called


r(t1) the cutter contact point (CC).
r(t)
Cutter center is called cutter location (CL).

CL at r(t1) is:

r(t1) + d U = r(t1) + d N
2 2 N

N is the normal vector.

04/19/20 10 - 4
©T.C. Chang

VECTOR PRODUCTS
a = a1 i + a2 j+ a3 k
b = b1 i + b2 j+ b3 k

Scalar product (dot product) b


 a
a  b = a1 b1 + a2 b2 + a3 b3
= a b cos 
|b| cos 

Vector product (cross product)


 b = a b sin  u
a
u
 i jk axb b
a  b = a1 a2 a3 |b| sin 
b1 b2 b3 

a
= (a2 b3 – a3 b2) i +
(a3 b1 – a1 b3) j + bxa

(a1 b3 – a2 b1) k

04/19/20 10 - 5
©T.C. Chang

MAPT LANGUAGE
User program
in MAPT

MAPT
MAPT LEX parser
grammar &
YACC MAPT
Language
Math processor Processor

Output
formatter

APT CL data MAPT CL data

04/19/20 10 - 6
©T.C. Chang

MAPT
GRAMMAR
Defining a point in YACC:

point_spec : coord_spec {
$$.X = $1.X; | xy_large_small ',' INTOF ',' circledef ','
$$.y = $1.y; circledef
$$.z = $1.z; } {
| linedef ',' linedef i = (int)$1;
{ j = (int)$5;
i = (int)$1; k = (int)$7;
j = (int)$3; gpt2cir(i,j,k,&$$); }
gp2line(i,j,&$$); } | xy_large_small ',' INTOF ',' linedef ',' circledef
| pointdef ',' coord_spec {
{ i = (int)$1;
j = (int)$5;
i = (int)$1;
k = (int)$7;
$$.x = pxyz[i].x + $3.x;
gptlncir(i,j,k,&$$);
$$.y = pxyz[i].y + $3.y;
}
$$.z = pxyz[i].z + $3.z; }
;
| CENTER ',' circledef
{
i = (int)$3;
$$.x = cirxyr[i].x;
$$.y = cirxyr[i].y;
$$.z = 0.; }

04/19/20 10 - 7
©T.C. Chang

DATA
typedef struct circletype {STRUCTURES
typedef struct planetype {
double x; double a;
double y; double b;
double r; double c;
} circletype, *circlePtr; double d;
} planetype, *planePtr;
typedef struct linetype {
double x1; typedef struct pocketype {
double y1; struct pocketype * prev;
double z1; struct pocketype * next;
double x2; int type;
double y2; double x;
double z2; double y;
} linetype, *linePtr; double z;
} pocketype;
typedef struct pointtype {
double x;
double y;
double z;
} pointtype, *pointPtr;
04/19/20 10 - 8
©T.C. Chang

PARSIN
e.g.
G
token - symbol

P1 = POINT / 5*6, sin(30), 10.0

token - id real number


token - major word
expression

After the analysis, the above input line matches the


following statement:

P-name = POINT/x,y,z

04/19/20 10 - 9
©T.C. Chang

SOLVING THE MATH PROBLEM


Find the intersection of two lines.

(x1 , y1 ) (x 2, y2)
x –x x –x
l 1 : y – y1 = y2 – y1 l1 l2
line 1: 1 2 1

(x3 , y3 ) (x 4, y4) x –x x –x
line 2: l 2 : y – y3 = y4 – y3
3 4 3

x –x x –x
let: a = y2 – y1 b = y4 – y3
2 1 4 3

Problems:
x –x x –x
l 1 : y – y1 = a l 2 : y – y3 = b
1 3 a = b : parallel lines, no solution
x – x 1 = a ( y – y1) (1) overflow in equation
x – x 3 = b ( y – y3) (2) y2 = y1 : l1 parallel to the x-axis.
(1) – (2) x3 – x1 = (a–b) y+ (a y1 – by3) "a" is infinite
(a–b) y = (x 3 – x1) – (a y1 – by3)
a  b
y2  y1
(x 3 – x1 ) – (a y1 – by 3)
y=
(a–b)

x = a ( y – y1 ) + x1
04/19/20 10 - 10
©T.C. Chang

MOTION STATEMENTS
GO{LFT,RGT}/L1,{TO,ON,PAST}, L2
l1
ON is easy, it is the
intersection
TO & PAST need offset
l2

Does each case need a set of equations?

Do not forget the special cases mentioned in the


previous slide.

04/19/20 10 - 11
©T.C. Chang

MOTION STATEMENTS
What if this is always the case:
y

x = 0.0  l2
y = y * – r  (0.,y*)
sin
(x,y)

l1

y = y * + flag r
sin 
x
– 1 To
flag= 0 On
1 Past

04/19/20 10 - 12
©T.C. Chang

USE TRANSFORMATION
We can make every problem as simple as the one shown before through
a transformation.

l1 make this the


y-axis
Procedure:

1. Find the angle between l1 and the  l2


y-axis, call it 
2. Build a transformation matrix which
translate to (a,b,c), and rotate about
the z-axis by  (a,b,c)
Set this as the new origin
3. Transform two points of l2.

cos  sin  0 0
Trans = – sin  cos  0 0
0 0 1 0
–a –b –c 1

4. After solving the problem, transform the result back. (-a,-b,-c), - 


04/19/20 10 - 13
©T.C. Chang

ANOTHER EXAMPLE
{GOLFT, GORGT} / L1, {TO,ON,PAST} , C1

Make an easy case:

What cases still need to be checked?

e.g. no intersection between line and circle


current position is inside the circle.

04/19/20 10 - 14
©T.C. Chang

3D CURVES AND
SURFACES
Parametric description of a curve.

r( t ) r = r( t) tmin  t  tmax
Z
Y
x = x(t)
X
y = y(t)
z = z(t)

Parametric description of a surface.

r = r( t,s) tmin  t  tmax, smin  s  smax

r( t , s )

04/19/20 10 - 15
©T.C. Chang

TANGENT AND
T =dr
NORMAL
is the tangent vector of curve r(t).
dt

Tangent vectors along t and s directions on a surface.


Tt  =  r
t
Ts =  r r
s s N
r
 t
N = Tt  Ts =  r   r
t  s

s
t

04/19/20 10 - 16
©T.C. Chang

CUTTER OFFSET
In 3-axis machining, the surface normal passes through the tool center.

CL = CC + d N
2 N
= r(t,s) + d N
2 N N

CL

CC

s
t

04/19/20 10 - 17
©T.C. Chang

SCULPTURED SURFACE
MACHINING
3-AXIS MACHINING - ball-end mill
5-AXIS MACHINING - flat-end mill, or filleted flat-end mill

Ball-end mills for 3-axis machining Flat-end & filleted flat-end mills

3-axis machining
fixed tool orientation 5-axis machining
change tool orientation

04/19/20 10 - 18
©T.C. Chang

CARTESIAN
CUTTING

s
t Interpolate on the surface based
Y
on the straight path on the X-Y
plane.
cutter path Difficult to solve the intersection
between a Cartesian equation
and a parametric equation.

y=a
r(t,s)

X
04/19/20 10 - 19
©T.C. Chang

ISOPARAMETER
MACHINING

Cut on t & s directions

Try to find the step size


in approximating the surface.
s t
The maximum error allowed
is smaller than or equal to
the tolerance.

Materials left on the surface


are ground off or scrapped off.

04/19/20 10 - 20
©T.C. Chang

FORWARD STEPPING
Move on the u direction first. Use step size u.

 = ui + u
ui+1

r(ui+1,v )j is the CC point.

N(ui+1,v )j
rCL = r(ui+1,v )j + dia
2 N(u ,v )
i+1 j
is the CL point

surface normal

ui+1 curve
e r(u,v )j
ui

e Š tolerance value

u
04/19/20 10 - 21
©T.C. Chang

SIDE STEPPING
Take a side step before moving on the next curve segment.
Side step v
v

vi+1 = vi + v

v u
v

Repeat forward stepping and side stepping until the entire surface
is machined.

04/19/20 10 - 22
©T.C. Chang

STEP SIZE
A quick and dirty approach:

Set an initial u, find the maximum cordal deviation. If the deviation is greater
than the tolerance, reduce u, and try again. Otherwise, the next step is found.
r(ui+ u)

r(ui)
 = ui + u
ui+1

Find three points on the curve segment.


ui  j= ui + 
ju
4 d2
d1 d3
r(ui )j – r(ui ) x r(ui+1) – r(ui) Ui+1
d j= Ui+2u/4
Ui+3u/4
r(ui+1) – r(ui) Ui+u/4
Ui

If max(d) > tolerance, set u, = 0.75 u, repeat the above step.
Otherwise stop.

04/19/20 10 - 23
©T.C. Chang

SIDE STEP

l = |r(vi + 1 – r(vi)|
r(vi +1)

r(vi ) l

Since the step size is small, l/2


we may approximate the curve
by a line.

vi+1 = vi + v dia/2

If  > tolerance v = 0.75 v
and repeat, otherwise stop
  dia – 2
( dia ) – ( l )
2
2 2 2

04/19/20 10 - 24
©T.C. Chang

PROBLEMS WITH THIS APPROACH

over estimate
under estimate
Convex surface Concave surface

Over estimate on convex surface. Under estimate on concave surface.

vi+1 curve
 tolerance
vi curve

 tolerance

Uneven cut on uneven surface.


04/19/20 10 - 25
©T.C. Chang

UTILITY CODES -
Point/line distance/Y angle
#include <math.h>
#include <stdio.h> /* find the angle between a line and the y axis */
#define eps1 0.00001 double
#define pi 3.1415 yangl(x1,y1,x2,y2)
double x1, y1, x2, y2;
typedef struct linetype { {
double x1; double dx, dy,ang;
double y1;
double z1; dx = x2 - x1;
double x2; dy = y2 - y1;
double y2; if (fabs(dy)>eps1){
double z2; ang =atan(-dx/dy);
} linetype, *linePtr; if (dy>0.0) return(ang);
if(ang>0.0) {ang = -pi+ang;}
/* find the distance between a point and a else { ang = pi+ang;}
line */ x,y
return(ang);
double
}else v1
dpl(x,y,x1,y1,x2,y2)
{ d
double x, y, x1, y1, x2, y2;
if (dx>0.0){
{
return( -pi/2.);
double ax, ay, bx, by, dl; v2
}else x1,y1 x2,y2
{
ax = x2 - x1;
return( pi/2.); v1 = (x–x1 ), ( y–y1)
ay = y2 - y1;
}
bx = x - x1; v2 = (x2–x1), (y2–y1)
}
by = y - y1; v v
} d = 1 2
dl = sqrt(ax*ax+ay*ay); v2
return(fabs(ax*by-ay*bx)/dl);
}
04/19/20 10 - 26
©T.C. Chang

UTILITY CODES
forward/backward transformation
/* tranform the object from x,y,z to x2,y2,z2
origin is x0,y0,z0, angle to the y axis is beta
dir = 0 transform
= 1 inverse transform
*/
void
tranf(dir,xi,yi,zi,beta,x1,y1,z1,x,y,z)
int dir;
double xi, yi, zi, beta, x1, y1, z1, *x, *y,
*z;
{
double dx,dy;

if(dir == 0){
dx = x1-xi;
dy = y1-yi;
*x = dx*cos(beta)+dy*sin(beta);
*y = -dx*sin(beta)+dy*cos(beta);
*z = z1;
} else if(dir == 1){
*x = xi+ x1*cos(beta)-y1*sin(beta);
*y = yi+ x1*sin(beta)+y1*cos(beta);
*z = z1;
}
}
04/19/20 10 - 27
©T.C. Chang

UTILITY CODES
forward/backward transformation
/* find the tangent lines from point to a circle
x1,y1,z1: Point x2,y2 r
x0,y0,r: circle
x = r *sqrt(1.0-(r/d)*(r/d));
1: left 0 right */ x0y0
if(lf_rgt == 1)x = -x;
void
glpntcir( x1,y1,z1,x0,y0,r, lf_rgt, ptr)
tranf(1,x1,y1,0.,beta,x,y,0.0,&
double x1,y1,z1,x0,y0,r; x2,&y2,&z);
linePtr ptr; ptr->x2= x2;
{ ptr->y2= y2;
double x,y,z,x2,y2; ptr->z2= z1; x1,y1
double d,d1, d2, beta;
}
d1 = (x1-x0)*(x1-x0);
d2 = (y1-y0)*(y1-y0);
d = sqrt(d1 + d2);
x0', y0'
if(d<= r) {
printf(" Point is inside the circle\n"); r
return;
}
/* transformation etc.*/
beta = yangl(x1,y1,x0,y0);
y = d - r*r/d;

x1' = 0,y1' = 0

04/19/20 10 - 28

You might also like