12 cm0268 geometric computing2

Upload: babu-kaala-pandian

Post on 02-Jun-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 12 CM0268 Geometric Computing2

    1/50

    CM0268MATLAB

    DSPGRAPHICS

    515

    Back

    Close

    Lines, Curves and Surfaces in 3D

    Lines in 3D

    In 3D theimplicit equationof a line is defined as theintersection oftwo planes. (More on this shortly)

    The parametric equation is a simple extension to 3D of the 2D form:

    x = x0+f t

    y = y0+gt

    z = z0+ht

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    2/50

    CM0268

    MATLAB

    DSPGRAPHICS

    516

    Back

    Close

    Parametric Lines in 3D

    v

    w

    tw

    v +tw

    v0= (x0, y0, z0)

    p= (x,y,z)

    x = x0+f t

    y = y0+gt

    z = z0+ht

    This is simply anextensionof the vector form in 3D

    The line is normalised whenf2 +g2 +h2 = 1

    http://lastpage/http://prevpage/http://goback/http://close/http://close/http://goback/http://prevpage/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    3/50

    CM0268

    MATLAB

    DSPGRAPHICS

    517

    Back

    Close

    Perpendicular Distance from a Point to a Line in 3D

    For the parametric form,

    x = x0+f ty = y0+gt

    z = z0+ht

    This builds on the 2D example we met earlier, line par point dist 2d.

    The 3D form isline par point dist 3d.dx = g * ( f * ( p ( 2 ) - y 0 ) - g * ( p(1) - x0 ) ) ...

    + h * ( f * ( p ( 3 ) - z 0 ) - h * ( p(1) - x0 ) );

    dy = h * ( g * ( p ( 3 ) - z 0 ) - h * ( p(2) - y0 ) ) ...

    - f * ( f * ( p ( 2 ) - y 0 ) - g * ( p(1) - x0 ) );

    d z = - f * ( f * ( p ( 3 ) - z 0 ) - h * ( p(1) - x0 ) ) ...

    - g * ( g * ( p ( 3 ) - z 0 ) - h * ( p(2) - y0 ) );

    dist = sqrt ( dx * dx + dy * dy + dz * dz ) ...

    / ( f * f + g * g + h * h );

    The value of parameter, t, where the point intersects the line isgiven by:t = (f*( p(1) - x0) + g*(p(2) - y0) + h*(p(3) - z0)/( f * f + g * g + h*h);

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_par_point_dist_2d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_par_point_dist_3d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_par_point_dist_3d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_par_point_dist_2d.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    4/50

    CM0268

    MATLAB

    DSPGRAPHICS

    518

    Back

    Close

    Line Through Two Points in 3D (parametric form)

    P

    Q

    The parametric form of a line through two points, P(xp, yp, zp)andQ(xq, yq, zq) comes readily from the vector form of line (again a simpleextension from 2D):

    Set base to pointPVector along line is(xqxp, yqyp, zqzp)The equation of the line is:

    x = xp+ (xqxp)ty = yp+ (yqyp)tz = zp+ (zqzp)t

    As in 2D,t = 0givesP andt = 1givesQNormalise if necessary.

    http://lastpage/http://prevpage/http://goback/http://close/http://close/http://goback/http://prevpage/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    5/50

    CM0268

    MATLAB

    DSPGRAPHICS

    519

    Back

    Close

    Implicit SurfacesAn implicit surface (just like implicit curves in 2D) of the form

    f(x,y,z ) = 0

    We simply add theextrazdimension.

    For example:

    A plane can be represented

    ax+by+cz+d= 0

    A sphere can be represented as

    (xxc)2 + (yyc)2 + (zzc)2 r2 = 0which is just the extension of the circle in 2D to 3D where thecentre is now(xc, yc, zc)and the radius isr.

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    6/50

    CM0268

    MATLAB

    DSPGRAPHICS

    520

    Back

    Close

    Implicit Equation of a Plane

    (a,b,c)

    O

    d

    The plane equation:

    ax+by+cz+d = 0

    Is normalised ifa2 +b2 +c2 =1.

    Like 2D thenormal vectorthe surface normal is given by avector n= (a,b,c)

    a, bandc are the cosine angles which the normal makes withthex-,y- andz-axes respectively.

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    7/50

    CM0268

    MATLAB

    DSPGRAPHICS

    521

    Back

    Close

    Parametric Equation of a Plane

    (f2, g2, h2)

    (f1, g1, h1)

    O

    (x0, y0, z0)

    x = x0+f1u+f2v

    y = y0+g1u+g2v

    z = z0+h1u+h2v

    This is an extension of parametric line into 3D where we nowhave two variable parametersuandv that vary.

    (f1, g1, h1) and (f2, g2, h2) are two different vectors parallel to theplane.

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    8/50

    CM0268

    MATLAB

    DSPGRAPHICS

    522

    Back

    Close

    Parametric Equation of a Plane (Cont.)

    (f2, g2, h2)

    (f1, g1, h1)

    O

    (x0, y0, z0)

    x = x0+f1u+f2v

    y = y0+g1u+g2vz = z0+h1u+h2v

    A point in the plane is found by adding proportion u of onevector to a proportionv of the other vector

    If the two vectors are have unit length and are perpendicular,then:

    f21+g2

    1+h2

    1 = 1

    f22+g2

    2+h2

    2 = 1

    f1f2+g1g2+h1h2 = 0 (scalar product)

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    9/50

    CM0268

    MATLAB

    DSPGRAPHICS

    523

    Back

    Close

    Distance from a 3D point and a Plane

    J(xj , yj, zj)

    d

    The distance,d, between a point,J(xj, yj, zj), and animplicitplane,ax+by+cz+d= 0is:

    d=axj+byj+czj+d

    a2 +b2 +c2

    This is very similar the 2D distance of a point to a line.

    The MATALB code to achive this is,plane imp point dist 3d.m:

    norm = sqrt ( a * a + b * b + c * c );

    if ( norm == 0.0

    error ( PLANE Normal = 0! );

    end

    dist = abs ( a * p(1) + b * p(2) + c * p(3) + d ) / norm;

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/plane_imp_point_dist_3d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/plane_imp_point_dist_3d.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    10/50

    CM0268

    MATLAB

    DSPGRAPHICS

    524

    Back

    Close

    Angle Between a Line and a Plane

    If the plane is in implicit formax+ by+cz+d = 0and line is inparametric form:

    x = x0+f t

    y = y0+gt

    z = z0+ht

    then the angle, between the line and the normal the plane (a,b,c)

    is:= cos1(af+bg+ch)

    The angle,, between the line and the plane is then:

    =

    2

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    11/50

    CM0268

    MATLAB

    DSPGRAPHICS

    525

    Back

    Close

    Angle Between a Line and a Plane (cont)

    If either line or plane equations are not normalised the we mustnormalise:

    = cos1 (af+bg+ch)

    (a2 +b2 +c2), = cos1

    (af+bg+ch)(f2 +g2 +h2)

    , = cos1 (af+bg+ch)

    (a2 +b2 +c2)(f2 +g2 +h2)

    The angle,, is as before:

    =

    2The MATLAB code to so this isplanes imp angle line 3d.m:

    norm1 = sqrt ( a1 * a1 + b1 * b1 + c1 * c1 );

    if ( norm1 == 0.0 )

    angle = Inf;

    return

    end

    norm2 = sqrt ( f * f + g *g + h * h );

    if ( norm2 == 0.0 )

    angle = Inf;

    return

    end

    cosine = ( a1 * f + b 1 * g + c 1 * h) / ( norm1 * norm2 );

    angle = pi/2 - acos( cosine );

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_imp_angle_line_3d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_imp_angle_line_3d.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    12/50

    CM0268

    MATLAB

    DSPGRAPHICS

    526

    Back

    Close

    Angle Between Two Planes

    Given twonormalisedimplicitplanes

    a1x+b1y+c1z+d1= 0

    and

    a2x+b2y+c2z+d2= 0

    The angle between them,, is the angle between the normals:

    = cos1(a1a2+b1b2+c1c2)

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    13/50

    CM0268

    MATLAB

    DSPGRAPHICS

    527

    Back

    Close

    Angle Between Two Planes (MATLAB Code)

    The MATLAB code to do this isplanes imp angle 3d.m:

    norm1 = sqrt ( a1 * a1 + b1 * b 1 + c 1 * c1 );if ( norm1 == 0.0 )

    angle = Inf;

    return

    end

    norm2 = sqrt ( a2 * a2 + b2 * b 2 + c 2 * c2 );

    if ( norm2 == 0.0 )angle = Inf;

    return

    end

    cosine = ( a1 * a2 + b1 * b2 + c1 * c2 ) / ( norm1 * norm2 );

    angle = acos ( cosine );

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_imp_angle_3d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_imp_angle_3d.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    14/50

    CM0268

    MATLAB

    DSPGRAPHICS

    528

    Back

    Close

    Intersection of a Line and Plane

    P(x, y)

    If the plane is in implicit formax+ by+cz+d = 0and line is inparametric form:

    x = x0+f t

    y = y0+gt

    z = z0+htThe the point,P(x, y), where the is given by parameter,t:

    t=(ax0+by0+cz0+d)

    af+bg+ch

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    15/50

    CM0268

    MATLAB

    DSPGRAPHICS

    529

    Back

    Close

    Intersection of a Line and Plane (MATLAB Code)

    The MATLAB code to do this isplane imp line par int 3d.m

    tol = eps;

    norm1 = sqrt ( a * a + b * b + c * c );if ( norm1 == 0.0 )

    error ( Norm1 = 0 - Fatal error! )

    end

    norm2 = sqrt ( f * f + g * g + h * h );

    if ( norm2 == 0.0 )

    error ( Norm2 = 0 - Fatal error! )

    end

    denom = a * f + b * g + c * h;

    if ( abs ( denom ) < tol * norm1 * norm2 ) % The line and the plane may be parallel.

    i f ( a * x 0 + b * y 0 + c * z 0 + d = = 0 . 0 )

    intersect = 1;

    p(1) = x0;

    p(2) = y0;

    p(3) = z0;

    else

    intersect = 0;

    p(1:dim_num) = 0.0;end

    else

    intersect = 1;

    t = - ( a * x 0 + b * y 0 + c * z0 + d ) / denom; % they must intersect.

    p(1) = x0 + t * f;

    p(2) = y0 + t * g;

    p(3) = z0 + t * h;

    end

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/plane_imp_line_par_int_3d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/plane_imp_line_par_int_3d.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    16/50

    CM0268

    MATLAB

    DSPGRAPHICS

    530

    Back

    Close

    Intersection of Three Planes

    Three planes intersect at point.Two planes intersect in a linetwo lines intersect at a pointSimilar problem to solving in 2D for two line intersecting:

    Solvethreesimultaneous linear equations:

    a1x+b1y+c1z+d1 = 0

    a2x+b2y+c2z+d2 = 0

    a3x+b3y+c3z+d3 = 0

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    17/50

    CM0268

    MATLAB

    DSPGRAPHICS

    531

    Back

    Close

    Intersection of Three Planes (MATLAB Code)

    The MATLAB code to do this is,planes 3d 3 intersect.m:

    tol = eps;

    b c = b 2*c 3 - b 3*c2;

    a c = a 2*c 3 - a 3*c2;

    a b = a 2*b 3 - a 3*b2;

    det = a1*b c - b 1*a c + c 1*ab

    if (abs(det) < tol)

    error(planes_3d_3_intersct: At least to planes are parallel);end;

    else

    d c = d 2*c 3 - d 3*c2;

    d b = d 2*b 3 - d 3*b2;

    a d = a 2*d 3 - a 3*d2;

    detinv = 1/det;

    p(1) = (b1*dc - d1*bc - c1*db)*detinv;p(2) = (d1*ac - a1*dc - c1*ad)*detinv;

    p(3) = (b1*ad + a1*db - d1*ab)*detinv;

    return;

    end;

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_3d_3_intersect.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_3d_3_intersect.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    18/50

    CM0268

    MATLAB

    DSPGRAPHICS

    532

    Back

    Close

    Intersection of Two Planes

    Two planes

    a1x+b1y+c1z+d1 = 0

    a2x+b2y+c2z+d2 = 0

    intersect to form a straight line:

    x = x0+f t

    y = y0+gt

    z = z0+ht

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    19/50

    CM0268

    MATLAB

    DSPGRAPHICS

    533

    Back

    Close

    Intersection of Two Planes (Cont.)

    (f , g , h)may be found by finding a vector along the line. This isgiven by the vector cross product of(a1, b1, c1)and(a2, b2, c2):

    f g ha1 b1 c1a2 b2 c2

    (x0, y0, z0)then readily follows.

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    20/50

    CM0268

    MATLAB

    DSPGRAPHICS

    534

    Back

    Close

    Intersection of Two Planes (Matlab Code)

    The MATLAB code to do this is,planes 3d 3 intersect.m:

    tol = eps;

    f = b 1*c 2 - b 2*c1;g = c 2*a 2 - c 2*a1;

    h = a 1*b 2 - a 2*b1;

    d e t = f*f + g*g + h*h;

    if (abs(det) < tol)

    error(planes_3d_2intersect_line: Planes are parallel);

    end;

    else

    d c = d 1*c 2 - c 1*d2;

    d b = d 1*b 2 - b 1*d2;

    a d = a 1*d 1 - a 2*d1;

    detinv = 1/det;

    x 0 = ( g*d c - h*db)*detinv;

    y0 = -(f*dc +h*ad)*detinv;

    z 0 = ( f*db +g*ab)*detinv;

    return;

    end;

    l h h h i

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_3d_3_intersect.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/planes_3d_3_intersect.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    21/50

    CM0268

    MATLABDSP

    GRAPHICS

    535

    Back

    Close

    Plane Through Three Points

    Just as two points define a line,three points define a plane (this is theexplicitform of a plane):

    Pk

    Pl

    Pj

    A plane may be found as follows:

    LetPjbe the to point(x0, y0, z0)in the planeForm two vectors in the planePlPjandPkPjForm another vector from a general pointP(x, y)in the plane to

    Pj

    The the equation of the plane is given by:

    xxj yyj zzjxkxj ykyj zkzjxlxj ylyj zlzj

    a, b, canddcan be found by expanding the determinant above

    Pl Th h Th P i (MATLAB C d )

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    22/50

    CM0268

    MATLABDSP

    GRAPHICS

    536

    Back

    Close

    Plane Through Three Points (MATLAB Code)

    The MATLAB code to do this,plane exp2imp 3d.m

    a = ( p2(2) - p1(2) ) * ( p3(3) - p1(3) ) ...

    - ( p2(3) - p1(3) ) * ( p3(2) - p1(2) );

    b = ( p2(3) - p1(3) ) * ( p3(1) - p1(1) ) ...

    - ( p2(1) - p1(1) ) * ( p3(3) - p1(3) );

    c = ( p2(1) - p1(1) ) * ( p3(2) - p1(2) ) ...

    - ( p2(2) - p1(2) ) * ( p3(1) - p1(1) );

    d = - p2(1) * a - p2(2) * b - p2(3) * c;

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/plane_exp2imp_3d.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/plane_exp2imp_3d.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    23/50

    CM0268

    MATLABDSP

    GRAPHICS

    537

    Back

    Close

    Parametric Surfaces

    The general form of a parametric surface is

    r= (x(u, v), y(u, v), z(u, v)).

    This is just like a parametric curve except we now have two

    parametersuandv that vary.

    u

    v

    P t i S f C li d

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    24/50

    CM0268

    MATLABDSP

    GRAPHICS

    538

    Back

    Close

    Parametric Surface: Cylinder

    For example, a cylindrical may be represented in parametric form as

    x= x0+r cos u y=y0+r sin u z=z0+v.

    !1 0

    1 2

    3 4

    5

    !3

    !2

    !1

    0

    1

    2

    3

    0

    2

    4

    6

    8

    10

    Parametric Surface: Cylinder (MATLAB Code

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    25/50

    CM0268

    MATLABDSP

    GRAPHICS

    539

    Back

    Close

    Parametric Surface: Cylinder (MATLAB Code

    The MATLAB code to plot the cylinder figure iscyl plot.m

    p0 = [2,0,0] % x_0, y_0, z_0

    r = 3; %radius

    n = 360;

    hold on;

    for v = 1:10

    for u = 1:360

    theta = ( 2.0 * pi * ( u - 1 ) ) / n;

    x = p0(1) + r * cos(theta);y = p0(2) + r * sin(theta);

    z = p0(3) + v;

    plot3(x,y,z);

    end

    end

    Parametric Surface: Sphere

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/cyl_plot.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/cyl_plot.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    26/50

    CM0268

    MATLABDSP

    GRAPHICS

    540

    Back

    Close

    Parametric Surface: Sphere

    A sphere is represented in parametric form as

    x= xc +sin(u) sin(v) y=yc +cos(u) sin(v) z=zc +cos(v)

    MATLAB code to produce a parametric sphere is at HyperSphere.m

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/HyperSphere.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/HyperSphere.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    27/50

    CM0268

    MATLABDSP

    GRAPHICS

    541

    Back

    Close

    Piecewise Shape Models

    Polygons

    A polygon is a 2D shape that is bounded by a closed path or circuit,composed of a finite sequence of straight line segments.

    We can represent a polygon by a series of connected lines:

    P1(x1, y1)

    P2(x2, y2)

    P3(x3, y3)

    P4(x4, y4)

    P5(x5, y5)

    P6(x6, y6)

    P7(x7, y7)

    e1

    e2

    e3

    e4e5e6

    e7

    Polygons (Cont )

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    28/50

    CM0268

    MATLABDSP

    GRAPHICS

    542

    Back

    Close

    Polygons (Cont.)

    P1(x1, y1)

    P2(x2, y2)

    P3(x3, y3)

    P4(x4, y4)

    P5(x5, y5)

    P6(x6, y6)

    P7(x7, y7)

    e1

    e2

    e3

    e4e5e6

    e7

    Each line is defined by two vertices the start and end points.

    We can define a data structure which stores a list of points(coordinate positions) and the edges define by indexes to twopoints:

    Points:{P1(x1, y1), P2(x2, y2), P3(x3, y3), . . .}Points define thegeometryof the polygon.

    Edges:Edges :{e1= (P1, P2), e2= (P2, P3), . . .Edges define thetopologyof the polygon.If you traverse the polygon points in an ordered direction

    (clockwise) then the lines define a closed shape with the insideon the right of each line.

    3D Objects: Boundary Representation

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    29/50

    CM0268

    MATLABDSP

    GRAPHICS

    543

    Back

    Close

    3D Objects: Boundary Representation

    In 3D we need to represent the objects faces, edges and vertices and

    how they are joined together:

    3D Objects: Boundary Representation

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    30/50

    CM0268

    MATLABDSP

    GRAPHICS

    544

    Back

    Close

    3D Objects: Boundary Representation

    Topology The topology of an object records the connectivity of

    the faces, edges and vertices. Thus,Each edge has a vertex at either end of it (e1is terminated by

    v1andv2), and,

    each edge has two faces, one on either side of it (edgee3 liesbetween facesf1andf2).

    A face is either represented as an implicit surface or as a parametricsurface

    Edges may be straight lines (like e1), circular arcs (like e4), andso on.

    Geometry This described the exact shape and position of each ofthe edges, faces and vertices. The geometry of a vertex is just itsposition in space as given by its(x,y,z )coordinates.

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    31/50

    CM0268

    MATLABDSP

    GRAPHICS

    545

    Back

    Close

    Geometric TransformationsSome Common Geometric Transformations:

    2D Scaling:

    xk 00 yk

    2D Rotation:

    cos sin sin cos 2D Shear (xaxis):

    1 k0 1

    2D Shear (yaxis): 1 0

    k 1

    3D Scaling: xk 0 00 yk 0

    0 0 zk

    3D Rotation aboutzaxis:

    cos sin 0 sin cos 00 0 1

    2D Translation(Homogeneous Coords):

    1 0 dx0 1 dy

    0 0 1

    Rotation and Translation

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    32/50

    CM0268

    MATLAB

    DSPGRAPHICS

    546

    Back

    Close

    Rotation and Translation

    Applying Geometric Transformations

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    33/50

    CM0268

    MATLAB

    DSPGRAPHICS

    547

    Back

    Close

    pp y g

    When applying geometric transformations to objects

    Rotate the point coordinate and vectors (normals etc.)Simply do matrix-vector multiplication

    For polygons and Boundary representations only need to applytransformation to the point (geometric) data the topology isunchanged

    Compound Geometric Transformations

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    34/50

    CM0268

    MATLAB

    DSPGRAPHICS

    548

    Back

    Close

    p

    It is a simple task to create compound transformations (e.g.A rotationfollowed by a translation:

    Perform Matrix-Matrix multiplications,e.g. T.RNote in general T.R= R.T (Basic non-commutative law of

    multiplication)

    One problem exists in that a 2D Translation cannotbe representedas a 2D matrix it must be represented a 3D matrix:

    T=

    1 0 dx0 1 dy

    0 0 1

    So how do we combine a 2D rotation R. = cos sin sin cos

    with a translation?

    We need to defineHomogeneous Coordinatesto deal with thisissue.

    Homogeneous Coordinates

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    35/50

    CM0268

    MATLAB

    DSPGRAPHICS

    549

    Back

    Close

    g

    To work in homogeneous coordinates do the following:

    Increase the dimension of the space by 1, i.e. 2D3D, 3D4D.We can now accommodate the translation matrix.

    Convert all standard other 2D transformations via the following:

    X X 0X X 0

    0 0 1

    where

    X XX X

    is the regular 2D transformation

    Perform compound transformation by matrix-matrixmultiplication in homogeneous matrices

    Homogeneous Coordinates Example: 2D Rotation

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    36/50

    CM0268

    MATLAB

    DSPGRAPHICS

    550

    Back

    Close

    g p

    The transformation for a 2D rotation (angle of rotationis:

    cos sin sin cos

    The correspondinghomogenous formis:

    cos sin 0 sin cos 00 0 1

    Compound Geometric Transformations MATLAB Examples

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    37/50

    CM0268

    MATLAB

    DSPGRAPHICS

    551

    Back

    Close

    Simply create the matrices for individual transformations inMATALB (2D, 3D or homogeneous)

    Assemble compound via matrix multiplication.

    Apply compound transform to coordinates/vectors etc. viamatrix-vector multiplication.

    2D Geometric Transformation MATLAB Demo Code

    3D Transformations

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/transformation.htmlhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/transformation.htmlhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    38/50

    CM0268

    MATLAB

    DSPGRAPHICS

    552

    Back

    Close

    3D Rotation aboutxaxis:

    1 0 00 cos sin 0 sin cos

    3D Rotation abouty axis:

    cos 0 sin 0 1 0

    sin 0 cos

    3D Rotation aboutzaxis:

    cos sin 0

    sin cos 0

    0 0 1

    3D Scaling:

    xk 0 00 yk 00 0 zk

    3D Translation(Homogeneous Coords (4D):

    1 0 0 dx0 1 0 dy0 0 1 dz0 0 0 1

    Need to put all 3D transformation into homogenous form forcompound transformations.

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    39/50

    CM0268

    MATLAB

    DSPGRAPHICS

    553

    Back

    Close

    Least Squares FittingWe have already seen that we need 2 points to define a line and 3

    points to define circle and a plane the minimum number of freeparameters.However, in many data processing applications we will have many

    more samples than the minimum number required.

    Errors in the positions of these points mean that in practice they

    do not all lie exactly on the expected line/curve/surface.

    Least squares approximation methods find the surface of the giventype which best represents the data points.

    Minimise some error function

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    40/50

    CM0268

    MATLAB

    DSPGRAPHICS

    554

    Back

    Close

    Least Squares Fit of a Line

    We use the general explicit equation of a line here:

    y=mx+c

    We can define an error,ias the distance from the line:

    i=yimxic

    Least Squares Fit of a Line (Cont.)

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    41/50

    CM0268

    MATLAB

    DSPGRAPHICS

    555

    Back

    Close

    The best fitting plane to a set ofnpoints{Pi}occurs when

    2 =

    2i =

    (yimxic)2is a minimum, where this and all subsequent sums are to be taken

    over all points,Pi, i= 1, . . . , n.This occurs when

    2

    m = 0

    2

    c = 0

    Least Squares Fit of a Line (Cont.)

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    42/50

    CM0268

    MATLAB

    DSPGRAPHICS

    556

    Back

    Close

    Now

    2

    m

    =

    2(yi

    mxi

    c)xi= 0

    2

    c = 2

    (yimxic) = 0

    which leads to

    yimxi

    nc = 0xiyim

    x2ic

    xi = 0

    which can be solved formandcto give:

    m = nxiyi

    xi yin

    x2i(

    xi)2

    c =

    yi

    x2i

    xi

    xiyi

    n

    x2i(

    xi)2

    Least Squares Fit of a Line (MATLAB Code)

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    43/50

    CM0268

    MATLAB

    DSPGRAPHICS

    557

    Back

    Close

    The MATLAB code to perform least squares line fitting is,line fit.m

    function [m c] = line_fit(x,y)

    [n1 n] = size(x);

    sumx = sum(x);

    sumy = sum(y);

    sumx2 = sum(x.*x);

    sumxy = sum(x.*y);

    det = n* sumx2 - sumx*sumx;

    m = ( n*sumxy - sumx*sumy)/det;

    c = (sumy*sumx2 - sumx*sumxy)/det;

    Seeline fit demo.mfor example call.

    http://lastpage/http://close/http://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_fit.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_fit_demo.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_fit_demo.mhttp://www.cs.cf.ac.uk/Dave/CM0268/Lecture_Examples/Computational_Geometry/line_fit.mhttp://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    44/50

    Least Squares Fit of a Plane (Cont.)

  • 8/10/2019 12 CM0268 Geometric Computing2

    45/50

    CM0268

    MATLAB

    DSPGRAPHICS

    559

    Back

    Close

    The best fitting plane to a set ofn points {Pi} occurs when 2 = 2iis a minimum, where this and all subsequent sums are to be takenover all points,Pi, i= 1, . . . , n.

    This occurs when2

    a = 0 (1)

    and2

    b = 0 (2)

    and and when2

    c = 0 (3)

    Least Squares Fit of a Plane (Cont.)

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    46/50

    CM0268

    MATLAB

    DSPGRAPHICS

    560

    Back

    Close

    Now 2

    a

    = 0gives:

    xizia

    x2ib

    xiyic

    xi= 0,

    and 2

    b = 0gives:yizia

    xiyib

    y2ic

    yi= 0,

    and 2

    c = 0gives

    zia

    xib

    yinc= 0.

    Simplifying a Least Squares Fit of a Plane

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    47/50

    CM0268

    MATLAB

    DSPGRAPHICS

    561

    Back

    Close

    Now, some of these sums can become quite large and any attempt tosolve the equations directly can lead to poor results due to rounding

    errors.

    One common method (for any least squares approximation) ofreducing the rounding errors is to re-express the coordinates ofeach point relative to the centre of gravity of the set of points,(xg, yg, zg).

    All subsequent calculations are performed under this translationwith the final results requiring the inverse translation to return tothe original coordinate system.

    The translation also simplifies our minimisation problem since nowi

    xi=i

    yi=i

    zi= 0.

    Least Squares Fit of a Plane (Cont.)

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    48/50

    CM0268

    MATLAB

    DSPGRAPHICS

    562

    Back

    Close

    Therefore, using the above fact in previous equations and solving fora, bandcgives:

    a = xizi

    y2i

    yizi

    xiyi

    x2

    i

    y2

    i(xiyi)2 , (4)

    b =

    yizi

    x2i

    xizi

    xiyi

    x2i

    y2i(

    xiyi)2 , (5)

    c = 0. (6)

    All we now need to do is to translate back.

    http://lastpage/http://close/http://close/http://lastpage/
  • 8/10/2019 12 CM0268 Geometric Computing2

    49/50

  • 8/10/2019 12 CM0268 Geometric Computing2

    50/50

    CM0268

    MATLAB

    DSPGRAPHICS

    564

    Back

    Close

    THEEND

    http://lastpage/http://close/http://close/http://lastpage/