Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User...

138
ECM2410: Graphics and Animation Clipping Clipping 1/16

Transcript of Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User...

Page 1: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

ECM2410: Graphics and Animation

Clipping

Clipping 1/16

Page 2: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 3: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 4: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 5: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 6: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 7: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 8: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 9: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 10: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 11: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 12: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 13: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 14: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 15: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Rendering and clipping

To render a sceneDetermine objects to be rendered.Transform objects to device space.Clip to:

Device boundaries.Viewport boundaries.User specified clipping path.

Draw in framebuffer.

Clipping to:

Avoid drawing outside device.User special effects, e.g.,

Scene outside a window

Clip to near and far viewing planes in 3D.

Rendering and Clipping Clipping 2/16

Page 16: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping

Line segments and otherprimitives may be specifiedoutside the viewport or devicespace.

Want to confine geometry to aclipping region.

Clipping region is commonly aconvex polygon

Clipping rectangle is mostfrequent case:

xmin ≤x ≤ xmax

ymin ≤y ≤ ymax

Clipping Clipping 3/16

Page 17: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping

Line segments and otherprimitives may be specifiedoutside the viewport or devicespace.

Want to confine geometry to aclipping region.

Clipping region is commonly aconvex polygon

Clipping rectangle is mostfrequent case:

xmin ≤x ≤ xmax

ymin ≤y ≤ ymax

Clipping Clipping 3/16

Page 18: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping

Line segments and otherprimitives may be specifiedoutside the viewport or devicespace.

Want to confine geometry to aclipping region.

Clipping region is commonly aconvex polygon

Clipping rectangle is mostfrequent case:

xmin ≤x ≤ xmax

ymin ≤y ≤ ymax

Clipping Clipping 3/16

Page 19: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping

Line segments and otherprimitives may be specifiedoutside the viewport or devicespace.

Want to confine geometry to aclipping region.

Clipping region is commonly aconvex polygon

Clipping rectangle is mostfrequent case:

xmin ≤x ≤ xmax

ymin ≤y ≤ ymax

Clipping Clipping 3/16

Page 20: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping

Line segments and otherprimitives may be specifiedoutside the viewport or devicespace.

Want to confine geometry to aclipping region.

Clipping region is commonly aconvex polygon

Clipping rectangle is mostfrequent case:

xmin ≤x ≤ xmax

ymin ≤y ≤ ymax

Clipping Clipping 3/16

Page 21: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping

Line segments and otherprimitives may be specifiedoutside the viewport or devicespace.

Want to confine geometry to aclipping region.

Clipping region is commonly aconvex polygon

Clipping rectangle is mostfrequent case:

xmin ≤x ≤ xmax

ymin ≤y ≤ ymax

Clipping Clipping 3/16

Page 22: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 23: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 24: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 25: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 26: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 27: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 28: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 29: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 30: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 31: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping Methods

Scan convert to an off-screen bitmap;copy clipped bitmap to framebuffer.Permits arbitrarily shaped clipping regions.

Scissor

Clip on the fly during scan conversion.Doesn’t require an extra bitmap and can be fast.

Analytic clipping

Calculate parts of the primitives that lie in the clip region.Simple and efficient for points and line segments.

Clipping / Methods Clipping 4/16

Page 32: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping to Arbitrary Regions

Offscreen FramebufferOffscreen

Render clipping region to offscreen bitmap.

Render scene to offscreen bitmap.

Transfer pointwise intersection to visible framebuffer.

Clipping / Arbitrary Regions Clipping 5/16

Page 33: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping to Arbitrary Regions

Offscreen FramebufferOffscreen

Render clipping region to offscreen bitmap.

Render scene to offscreen bitmap.

Transfer pointwise intersection to visible framebuffer.

Clipping / Arbitrary Regions Clipping 5/16

Page 34: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping to Arbitrary Regions

Offscreen FramebufferOffscreen

Render clipping region to offscreen bitmap.

Render scene to offscreen bitmap.

Transfer pointwise intersection to visible framebuffer.

Clipping / Arbitrary Regions Clipping 5/16

Page 35: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping to Arbitrary Regions

Offscreen FramebufferOffscreen

Render clipping region to offscreen bitmap.

Render scene to offscreen bitmap.

Transfer pointwise intersection to visible framebuffer.

Clipping / Arbitrary Regions Clipping 5/16

Page 36: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping to Arbitrary Regions

Offscreen FramebufferOffscreen

Render clipping region to offscreen bitmap.

Render scene to offscreen bitmap.

Transfer pointwise intersection to visible framebuffer.

Clipping / Arbitrary Regions Clipping 5/16

Page 37: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 38: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 39: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 40: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 41: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 42: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 43: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 44: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 45: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 46: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 47: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 48: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 49: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Point Clipping

Keep point if it is inside the clipping region.Keep point if it satisfies:

xmin ≤ x ≤ xmax

ymin ≤ y ≤ ymax

Question:How to generalise to

Arbitrary Convex Polygons?Arbitrary Concave Polygons?

Answer:

See Hearn & Baker, Foley et al.

Point Clipping Clipping 6/16

Page 50: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 51: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 52: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 53: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 54: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 55: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 56: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 57: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 58: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 59: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 60: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 61: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 62: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Clipping line segments

Both endpoints inside clipping region.Trivial acceptance.One endpoint inside, one endpoint outside.There must be an intersection point p withedge of clip region;replace outside endpoint with p.

No endpoint insideNo intersection with clipping regionReject segment.

Intersections with 2 edges of clipping regionReplace segment with segment between the two crossingpoints

Result must be either a single segment or vacuous.

Clipping Line Segments Clipping 7/16

Page 63: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1

(x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 64: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1

(x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 65: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 66: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 67: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 68: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 69: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 70: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 71: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 72: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Calculating Intersections

Parametric representation of line segments

x = x1 + t(x2 − x1)

y = y1 + t(y2 − y1)

To find intersection with ymin, put y = ymin:

t∗ =ymin − y1

y2 − y1 (x1, y1)

(x2, y2)

ymin

If 0 ≤ t∗ ≤ 1 then the line segment intersects ymin at t∗

Thus x coordinate of intersection is x = x1 + t∗(x2 − x1)

Otherwise the line segment does not intersect ymin

Clipping Line Segments / Intersections Clipping 8/16

Page 73: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Brute Force Clipping

A. Classify endpoints to identifyrelevant case.4 comparisons per endpoint.

B. Compute intersection with each clip region edge to findintersection points.Intersection with each edge may have to be calculated.

Expensive – lots of redundant intersection calculations.

Brute Force Clipping Clipping 9/16

Page 74: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Brute Force Clipping

A. Classify endpoints to identifyrelevant case.4 comparisons per endpoint.

B. Compute intersection with each clip region edge to findintersection points.Intersection with each edge may have to be calculated.

Expensive – lots of redundant intersection calculations.

Brute Force Clipping Clipping 9/16

Page 75: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Brute Force Clipping

A. Classify endpoints to identifyrelevant case.4 comparisons per endpoint.

B. Compute intersection with each clip region edge to findintersection points.Intersection with each edge may have to be calculated.

Expensive – lots of redundant intersection calculations.

Brute Force Clipping Clipping 9/16

Page 76: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Brute Force Clipping

A. Classify endpoints to identifyrelevant case.4 comparisons per endpoint.

B. Compute intersection with each clip region edge to findintersection points.Intersection with each edge may have to be calculated.

Expensive – lots of redundant intersection calculations.

Brute Force Clipping Clipping 9/16

Page 77: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Brute Force Clipping

A. Classify endpoints to identifyrelevant case.4 comparisons per endpoint.

B. Compute intersection with each clip region edge to findintersection points.Intersection with each edge may have to be calculated.

Expensive – lots of redundant intersection calculations.

Brute Force Clipping Clipping 9/16

Page 78: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Brute Force Clipping

A. Classify endpoints to identifyrelevant case.4 comparisons per endpoint.

B. Compute intersection with each clip region edge to findintersection points.Intersection with each edge may have to be calculated.

Expensive – lots of redundant intersection calculations.

Brute Force Clipping Clipping 9/16

Page 79: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Brute Force Clipping

A. Classify endpoints to identifyrelevant case.4 comparisons per endpoint.

B. Compute intersection with each clip region edge to findintersection points.Intersection with each edge may have to be calculated.

Expensive – lots of redundant intersection calculations.

Brute Force Clipping Clipping 9/16

Page 80: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 81: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 82: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 83: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 84: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 85: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 86: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 87: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 88: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 89: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 90: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Cohen-Sutherland Algorithm

TBRL

0000

1000 1010

0010

01100100

1001

0001

0101

TBRL

TBRL

1. Classify each endpoint with respect toTop, Bottom, Right and Lefthalfplanes:

outside top: y > ymax

outside bottom: y < ymin

outside right: x > xmax

outside left: x < xmin

(Found from sign bit of the difference)

2. Assemble classifications into 4 bitoutcode for each endpoint.

3. Trivial acceptance if bitwise or ofoutcodes is zero.

4. Trivial rejection if bitwise and ofoutcodes is non-zero.

Cohen-Sutherland Algorithm Clipping 10/16

Page 91: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Exercise

Find the outcodes for the line segments:

Cohen-Sutherland Algorithm / Exercise Clipping 11/16

Page 92: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Exercise

Find the outcodes for the line segments:

Cohen-Sutherland Algorithm / Exercise Clipping 11/16

Page 93: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Exercise

Find the outcodes for the line segments:

Cohen-Sutherland Algorithm / Exercise Clipping 11/16

Page 94: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Outline

Each 1 bit in the outcode corresponds to a crossed boundary.

TBRL

0000

0000

01001

2

3

While not trivial acceptance or rejection:

Clip segment to boundaries in turn.A 1 in the outcode indicates thatend of the line should be clipped.

After each clip recompute outcodefor appropriate endpoint.

Cohen-Sutherland Algorithm / Solution Clipping 12/16

Page 95: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Outline

Each 1 bit in the outcode corresponds to a crossed boundary.

TBRL

0000

0000

01001

2

3

While not trivial acceptance or rejection:

Clip segment to boundaries in turn.A 1 in the outcode indicates thatend of the line should be clipped.

After each clip recompute outcodefor appropriate endpoint.

Cohen-Sutherland Algorithm / Solution Clipping 12/16

Page 96: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Outline

Each 1 bit in the outcode corresponds to a crossed boundary.

TBRL

0000

0000

01001

2

3

While not trivial acceptance or rejection:

Clip segment to boundaries in turn.A 1 in the outcode indicates thatend of the line should be clipped.

After each clip recompute outcodefor appropriate endpoint.

Cohen-Sutherland Algorithm / Solution Clipping 12/16

Page 97: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Outline

Each 1 bit in the outcode corresponds to a crossed boundary.

TBRL

0000

0000

01001

2

3

While not trivial acceptance or rejection:

Clip segment to boundaries in turn.A 1 in the outcode indicates thatend of the line should be clipped.

After each clip recompute outcodefor appropriate endpoint.

Cohen-Sutherland Algorithm / Solution Clipping 12/16

Page 98: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Outline

Each 1 bit in the outcode corresponds to a crossed boundary.

TBRL

0000

0000

01001

2

3

While not trivial acceptance or rejection:

Clip segment to boundaries in turn.A 1 in the outcode indicates thatend of the line should be clipped.

After each clip recompute outcodefor appropriate endpoint.

Cohen-Sutherland Algorithm / Solution Clipping 12/16

Page 99: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Outline

Each 1 bit in the outcode corresponds to a crossed boundary.

TBRL

0000

0000

01001

2

3

While not trivial acceptance or rejection:

Clip segment to boundaries in turn.A 1 in the outcode indicates thatend of the line should be clipped.

After each clip recompute outcodefor appropriate endpoint.

Cohen-Sutherland Algorithm / Solution Clipping 12/16

Page 100: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Outline

Each 1 bit in the outcode corresponds to a crossed boundary.

TBRL

0000

0000

01001

2

3

While not trivial acceptance or rejection:

Clip segment to boundaries in turn.A 1 in the outcode indicates thatend of the line should be clipped.

After each clip recompute outcodefor appropriate endpoint.

Cohen-Sutherland Algorithm / Solution Clipping 12/16

Page 101: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

0001

1000

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 102: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

0001

1000

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 103: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

0001

1000

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 104: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

0001

1000

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 105: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

0001

1000

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 106: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

1000

10001

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 107: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

1000

10001

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 108: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

1000

10001

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 109: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Green Line

TBRL

1000

10001

OutcodeInitial 0001 and 1000 = 0000

Clip left 1000 and 1000 = 10001000 or 1000 = 1000Trivial Rejection

Cohen-Sutherland Algorithm / Solution: Green Line Clipping 13/16

Page 110: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

0101

1010

OutcodesInitial 0100 and 1010

= 0000

Clip left 0100 and 1010

= 0000

Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 111: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

0101

1010

OutcodesInitial 0100 and 1010

= 0000

Clip left 0100 and 1010

= 0000

Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 112: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

0101

1010

OutcodesInitial 0100 and 1010

= 0000

Clip left 0100 and 1010

= 0000

Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 113: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

0101

1010

OutcodesInitial 0100 and 1010

= 0000

Clip left 0100 and 1010

= 0000

Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 114: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

0101

1010

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010

= 0000

Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 115: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

1010

10100

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010

= 0000

Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 116: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

1010

10100

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010 = 0000Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 117: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

1

20000

0100

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010 = 0000Clip right 0100 and 0000

= 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 118: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

1

20000

0100

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010 = 0000Clip right 0100 and 0000 = 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 119: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

20000

3

0000

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010 = 0000Clip right 0100 and 0000 = 0000

Clip bottom 0000 or 0000

= 0000

Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 120: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

20000

3

0000

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010 = 0000Clip right 0100 and 0000 = 0000

Clip bottom 0000 or 0000 = 0000Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 121: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Solution: Red Line

TBRL

20000

3

0000

OutcodesInitial 0100 and 1010 = 0000

Clip left 0100 and 1010 = 0000Clip right 0100 and 0000 = 0000

Clip bottom 0000 or 0000 = 0000Trivial Acceptance

Cohen-Sutherland Algorithm / Solution: Red Line Clipping 14/16

Page 122: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 123: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 124: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 125: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 126: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 127: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 128: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 129: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 130: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 131: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 132: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line clipping

Cohen-Sutherland

Reduces intersection calculations by identify clippingboundaries.Easily extended to three dimensions (clipping to a box).

but Some line segments are clipped more than once beforeacceptance or rejection.

AlternativesLiang-Barsky fewer intersection calculations.

works in 3D.can be extended to convex polygons.

Nicholl-Lee-Nicholl efficient in 2D; cannot be extended to 3D.

See: Hearn & Baker, section 6.5 onwardsFoley, van Dam, Steiner, Hughes

Cohen-Sutherland Algorithm / Advanced Line Clipping Clipping 15/16

Page 133: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line Clipping to Concave Polygons

Split concave polygon intounion of convex polygons.

Clip to each convexpolygon in turn.

Liang-Barsky clipping foreach polygon.

Most efficient to chooselarge polygons.

Line Clipping to Concave Polygons Clipping 16/16

Page 134: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line Clipping to Concave Polygons

Split concave polygon intounion of convex polygons.

Clip to each convexpolygon in turn.

Liang-Barsky clipping foreach polygon.

Most efficient to chooselarge polygons.

Line Clipping to Concave Polygons Clipping 16/16

Page 135: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line Clipping to Concave Polygons

Split concave polygon intounion of convex polygons.

Clip to each convexpolygon in turn.

Liang-Barsky clipping foreach polygon.

Most efficient to chooselarge polygons.

Line Clipping to Concave Polygons Clipping 16/16

Page 136: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line Clipping to Concave Polygons

Split concave polygon intounion of convex polygons.

Clip to each convexpolygon in turn.

Liang-Barsky clipping foreach polygon.

Most efficient to chooselarge polygons.

Line Clipping to Concave Polygons Clipping 16/16

Page 137: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line Clipping to Concave Polygons

Split concave polygon intounion of convex polygons.

Clip to each convexpolygon in turn.

Liang-Barsky clipping foreach polygon.

Most efficient to chooselarge polygons.

Line Clipping to Concave Polygons Clipping 16/16

Page 138: Clipping - empslocal.ex.ac.ukempslocal.ex.ac.uk/people/staff/pjk205/ECM2410/slides06.pdf · User specified clipping path. Draw in framebuffer. Clippingto: Avoid drawing outside device.

Line Clipping to Concave Polygons

Split concave polygon intounion of convex polygons.

Clip to each convexpolygon in turn.

Liang-Barsky clipping foreach polygon.

Most efficient to chooselarge polygons.

Line Clipping to Concave Polygons Clipping 16/16