Total members 10261 | Gratitudes |It is currently Wed May 23, 2012 9:11 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Line Rotation 2D
PostPosted: Tue Apr 17, 2007 3:08 pm 
Offline
Newbie
User avatar

Joined: Thu Apr 05, 2007 9:57 pm
Posts: 17
Has thanked: 0 time
Have thanks: 0 time

This a java program for line rotation.
Using the following rule :

X2 =X1*cos(theta)-Y1*sin(theta);
Y2 =X1*sin(theta)+Y1*cos(theta);
Attachment:
File comment: Line Rotation
Rotation.GIF
Rotation.GIF [ 5.29 KiB | Viewed 7666 times ]

Code:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;

/**
*
* @author mohamed
*  www.codemiles.com
*/
public class Line_Rotation  extends JFrame{
   
    /** Creates a new instance of Translation */

    private int width=400;
    private int height=400;
    private int x1=100;
    private int y1=100;
    private int x2;
    private int y2;
    private float theta=15;
   
    public Line_Rotation() {
         setTitle("Line Translation");
         setSize(width,height);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         setVisible(true);
    }
      public void paint(Graphics g) {
       g.fillRect(0,0,400,400);
        g.setColor(Color.RED);

g.drawLine(200,200,x1+200,200-y1);
             g.setColor(Color.GREEN);
             x2=((int)(x1*Math.cos(theta*Math.PI/180)))-((int)(y1* Math.sin(theta*Math.PI/180)));
             y2=((int)(x1*Math.sin(theta*Math.PI/180)))+((int)(y1* Math.cos(theta*Math.PI/180)));
                g.drawLine(200,200,x2+200,200-y2);
     
    }
      public static void main(String[] args) {
        // TODO code application logic here
    new Line_Rotation();
    }

}


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Changing the line height of the paragraph
 draw a horizontal line in your html page
 start a new line in html
 Command line chat (client and server)
 Help needed to verify a new on-line C test
 the text file i saved all in one line. How can i solve it?
 c program - command line prompt - need help
 read from command line
 Rotation in java
 Line Styles in java

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team