1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yarga [219]
3 years ago
15

Write a program that, for four points A, B, C and P, which a) Draws a triangle formed by ABC and a small cross showing the posit

ion of P b) Displays a line of text indicating which of the following three cases applies: P lies • Inside ABC • Outside ABC • On an edge of ABC. The user will specify the four points by clicking.
Computers and Technology
1 answer:
Degger [83]3 years ago
6 0

Answer:

import java.awt.*;

import java.applet.*;

public class DrawTrainlge extends Applet{

static double findDistance(float x1, float y1,float a, float b,float c){

double dis = Math.abs(((a * x1 + b * y1 + c)) /  (Math.sqrt(a * a + b * b)));

return dis;

}

public void paint(Graphics g){

Point[] point = new Point[4];

g.drawLine(point[0].x , point[0].y , point[1].x , point[1].y);

g.drawLine(point[0].x , point[0].y , point[2].x , point[2].y);

g.drawLine(point[2].x , point[2].y , point[1].x , point[1].y);

double newdistance = 9999999;

for(int i=0;i<3;i++){

            int first = (i+1)%3;

            int second = i;

            float a = point[first].y - point[second].y;

            float b = point[second].x - point[first].x;

            float c = a*(point[second].x) + b*(point[second].y);

            double dis = findDistance(point[3].x,point[3].y,a,b,c);

            if(newdistance > dis){

               dis = newdistance;

         }

}

g.drawString("Shortest Distance");

g.drawString(dis);

}

}

Explanation:

  • Inside the findDistance method, find the distance  by using the following formula:

Math.abs(((a * x1 + b * y1 + c)) /  (Math.sqrt(a * a + b * b)))

  • Inside the paint method, give your input in the form of four points(A,B,C,D) .
You might be interested in
Perform depth-first search on each of the following graphs; whenever there's a choice of vertices, pick the one that is alphabet
Vikki [24]

Answer:

See the table attached for complete solution to the problem.

7 0
3 years ago
If you are trying move a hard drive from a non-working computer to a working computer for the purposes of accessing the data on
Llana [10]
You must have an administrator password before you can access the drive <span />
5 0
3 years ago
Which option ensures that a page break is automatically inserted ahead of a specific paragraph or heading?
gulaghasi [49]

The correct answer is option D, the last one! <3

6 0
3 years ago
Read 2 more answers
What is an compiler?
marissa [1.9K]
The accurate answer is

A compiler takes your source code, it converts the entire thing into machine language and then stores these equivalent machine language instructions in a separate file. We programmers call that the "executable file.

Glad to help :)<span />
6 0
4 years ago
Read 2 more answers
Professor Midas drives an automobile from Newark to Reno along Interstate 80. His car’s gas tank, when full, holds enough gas
zmey [24]

Answer:

The GREEDY Algorithm

Explanation:

Based on the situation given in question, the Greedy algorithm shall give the optimal solution to professor

Suppose that the cities are at locations0 =x0< x1< . . . < x

We shall use the induction method to prove that G is the optimal solution valid for numbers less than n

We assume another solution Z which we initially consider to be optimum as well, based on that when Z fills the tank, it fills it to full level

Let us state the values in case of n intervals. Given below, we say that g1 is the first stop and z1 is also the first stop.

This can be written as ;

G=g1, g2, . . . , gk

Z=z1, z2, . . . , zk’

Here k’ <= k and k < n

Let I be an idex where for the first time gi is not equal to zi

Considering t= maxi Zi

Z′=g1, z2, z3, . . . , zk′

Now since z2, z3, . . . , zk′ should be an optimal stopping pattern for the problem otherwise we have chosen Z, with smaller gas filling (not feasible)

Using induction hypothesis we conclude thatg2, . . . , gk is an optimal stopping pattern, which is based on greedy algorithm

7 0
3 years ago
Other questions:
  • What auto-generated elements can be added to the header and footer? A. Charts and Images B. Theme and Font Selection C. Author a
    8·2 answers
  • You would like to arrange the records alphabetically. You should _____.
    7·2 answers
  • Kai is a software engineer who started his own IT consulting firm. His friend, Catalina, is the owner of a store that sells offi
    13·2 answers
  • Write a program that asks the user for three strings. Then, print out whether the first string concatenated to the second string
    8·1 answer
  • Which two statements are true about the Data Sync functionality? (Choose two.)
    15·1 answer
  • In Java; Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or
    10·1 answer
  • Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp
    11·1 answer
  • How does violating the SOLID principles make code hard to test?
    5·1 answer
  • There are....... section in<br>cpu<br>​
    15·1 answer
  • Why is experience in their own factory setting
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!