Introduction Graphics are an important component of almost any software system t
ID: 3562297 • Letter: I
Question
Introduction
Graphics are an important component of almost any software system these days. We will look at various ways that software can manage and display graphics. One very important approach to graphics makes use of geometric figures. With this lab we begin to look at ways that geometric figures can be represented in programs and manipulated.
This lab concerns lines and points, the two most basic geometric objects. We will use an analytic representation. For points, this will be familiar, a point is represented by its two coordinates, x and y. The representation we user for lines is a common one in geometry. What may seem different is that only part of that representation is captured in an object.
The major objectives of this assignment are that you practice representing common objects in Java code and that you learn how to apply formulas and algorithms in context.
Project Organization
The source files in this project must be organized in a certain way.
The file TestPointLine.java is a test program for your two classes.
Class Specifications
Create two classes named Point and Line that have the following attributes:
In analytic geometry a line is represented by an equation in x and y. For example, y = 3?x+5. To represent this line as an object of class Line we must convert the equation of the line to a standard form: 3?x + (-1)?y + 5 = 0. Then the Line object would have a = 3, b = -1 and c = 5. Notice that x and y are not represented in the Lineobject, just the coefficients.
The Line and Point classes are going to have several methods.
This method should return the distance from this line to the point p. See the discussion below for formulas.
In applying the formula below, note that x0 is the x attribute of p and similarly for y0 The a, b and c for the formula are the attributes of the Line object this.
This method should return the distance from this point to the the point p. See the discussion below for formulas.
The coordinates used in computing the distance formula given below are the attributes of the Point object pand the attributes of the Point object this.
Formulas
Distance between two points
We want to compute the distance between two points (x1,y1) and (x2,y2). This is given by the square root of
So, this method computes the formula and returns it.1
Distance from a point to a line
We want to compute the distance from the point with coordinates (x0 ,y0) and the line given by the equation a?x + b?y + c = 0.
Start by computing the square root of a2 + b2. Call this value denom. Compute the absolute value ofa?x0+b?y0+c and divide it by denom. This is the distance value we want to compute.1
Explanation / Answer
The file TestPointLine.java is a test program for your two classes.
Class Specifications
Create two classes named Point and Line that have the following attributes:
In analytic geometry a line is represented by an equation in x and y. For example, y = 3?x+5. To represent this line as an object of class Line we must convert the equation of the line to a standard form: 3?x + (-1)?y + 5 = 0. Then the Line object would have a = 3, b = -1 and c = 5. Notice that x and y are not represented in the Line object, just the coefficients.
The Line and Point classes are going to have several methods.
This method should return the distance from this line to the point p. See the discussion below for formulas.
In applying the formula below, note that x0 is the x attribute of p and similarly for y0 The a, b and c for the formula are the attributes of the Line object this.
This method should return the distance from this point to the the point p. See the discussion below for formulas.
The coordinates used in computing the distance formula given below are the attributes of the Point object p and the attributes of the Point object this.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.