Detererming a Point's Position with respect to a line - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Detererming a Point's Position with respect to a line

Description:

We need to be able to tell whether a pixel is above or below a non-vertical line ... Thus, given a test point (x, y), we compute y' that corresponds to x and lies on ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 10
Provided by: rlo60
Category:

less

Transcript and Presenter's Notes

Title: Detererming a Point's Position with respect to a line


1
Detererming a Point's Position with respect to a
line
  • Generating PPM files for signal flags

2
Signal Flag
  • Suppose we want to produce the following signal
    flag

3
A Point's Position with respect to a line
  • We need to be able to tell whether a pixel is
    above or below a non-vertical line
  • Two points, ,
    determine a line.
  • The slope of the line is

4
A Point's Position with respect to a line
  • The coordinates of any arbitrary point (x, y)
    that lies on the line is
  • Thus, given a test point (x, y), we compute y'
    that corresponds to x and lies on the line
  • If y' gt y, then (x, y) lies below the line
    otherwise, (x, y) lies above the line.

5
Generating the signal flag
  • / signal.c /
  • include ltstdio.hgt
  • include ltstdlib.hgt
  • int isAbove (int x, int y, int x1, int y1, int
    x2, int y2)
  • void makeHeader( int width, int height)
  • int main( )
  • int width
  • int height
  • int x
  • int y 0

6
Generating the signal flag
  • fscanf(stdin, "d", width)
  • fscanf(stdin, "d", height)
  • makeHeader(width, height)
  • while(y lt height)
  • x 0
  • while(x lt width)
  • if(isAbove(x, y, 0, 0, width,
    height))
  • printf("ccc", 255, 255, 0)
  • else
  • printf("ccc", 255, 0, 0)
  • x x 1
  • y y 1

7
Generating the signal flag
  • /
  • This function determines if a given point is
    above/below the line containing (x1,y1) and (x2,
    y2).
  • It returns 1 if the point is above the line
    otherwise it returns 0.

  • /
  • int isAbove(int x, int y, int x1, int y1, int x2,
    int y2)
  • float slope
  • float yValue // corresponds to y
    in the equation on slide 4
  • int out
  • // INSERT CODE TO COMPUTE THE SLOPE OF THE
    LINE
  • // INSERT CODE TO COMPUTE yValue USING THE
    EQUATION ON SLIDE 4
  • if (yValue gt y)
  • out 1
  • else
  • out 0

8
Generating the signal flag
  • /
  • This function writes the header to standard
    output

  • /
  • void makeHeader(int w, int h)
  • fprintf(stdout, "P6\n")
  • fprintf(stdout, "d d d\n", w, h, 255)

9
Another signal flag
  • Suppose we want to produce the following signal
    flag?
Write a Comment
User Comments (0)
About PowerShow.com