-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLine3D.java
More file actions
39 lines (34 loc) · 868 Bytes
/
Line3D.java
File metadata and controls
39 lines (34 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.awt.*;
public class Line3D
{
public Point3D point1;
public Point3D point2;
public Color color=Color.BLUE;
public Line3D(Point3D p1, Point3D p2)
{
point1=p1;
point2=p2;
}
public Point getScreenPoint(Point3D point, Point p, double d)
{
Vect direc= new Vect(p,new Point(point.x,point.y));
direc.multiply(d/(d+point.z));
if(point.z>=0)
return direc.getPointFrom(p);
return new Point(0,0);
}
public void printLine(Graphics page, Point p, double d)
{
if(!(point1.z<=0||point2.z<=0))
{
Point s1=getScreenPoint(point1,p,d);
Point s2=getScreenPoint(point2,p,d);
page.setColor(color);
page.drawLine((int)s1.x,(int)s1.y,(int)s2.x,(int)s2.y);
}
}
public Point3D getMidpoint()
{
return new Point3D((point1.x+point2.x)/2,(point1.y+point2.y)/2,(point1.z+point2.z)/2);
}
}