[JAVA100 Case]031, three-dimensional cube

Source: Internet
Author: User
Tags cos sin

Import java.awt.*
Import javax.swing.*
public class gr3d4a extends gr3d1m {

/**
*<br> Method Description: Main method
*<br> input parameter:
*<br> return type:
*/
public static void Main (string[] args) {
gr3d4a G3 = New gr3d4a ();
}
/**
*<br> method Description: Builder
*<br> input parameters:
*<br> return type:
*/
Public gr3d4a () {
Sett Itle ("3D Cube Box");
Setdefaultcloseoperation (jframe.dispose_on_close);
Addmouselistener (this);
Addmousemotionlistener (this);
SetBackground (New Color (128,128,255));
SetSize (350,350);
Show ();
}
/**
*<br> Method Description: Draw a Cube box, overload the method in gr3d1m
*<br> input parameters:
*<br> return type:
*/
Public void Drawpg (Graphics g,double []x,double []y,
Double []z,int xp,int Yp,color Co) {
Double x1,y1,z0;< br> int len=x.length;
Double [] xw=new Double[len];
Double [] yw=new Double[len];
int [] xx=new int [Len];
Int []yy=new int [Len];
Final double rad=math.pi/180.0;
Double A=angx*rad;
Double B=angy*rad;
Double Sina=math.sin (a), Sinb=math.sin (b);
Double Cosa=math.cos (a), Cosb=math.cos (b);     
for (int i=0; i<len; i++) {
x1= x[i]*cosb+z[i]*sinb;
Z0=-X[I]*SINB+Z[I]*COSB;
y1= Y[i]*cosa-z0*sina;
xx[i]=xp+ (int) math.rint (x1);
yy[i]=yp-(int) math.rint (y1);
Xw[i]=x1; yw[i]=y1;     
}
if (Hvec (XW,YW) > 0) {
G.setcolor (CO);
G.fillpolygon (Xx,yy,len);//filled Polygon
}
}
/**
*<br> method Description: Shadow processing, if the plane is obscured will not be drawn
*<br> input parameters:
*<br> return Type:
*/
Double Hvec (double []x,double []y) {
Returns (x[0]* (y[1]-y[2)) +x[1]* (y[2]-y[0]) +x[2 ]* (y[0]-y[1]));
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.