Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2008, 08:32 AM
Member
 
Join Date: Jan 2008
Posts: 7
sandhyau is on a distinguished road
how u rotate the arrow mark as the line moves accordingly
can any one help me how the angles of the arrow mark should rotate as the line moves accordingly. here i am placing the code for arrow mark in the fixed angle.


AffineTransform at = AffineTransform.getTranslateInstance((point2.x + point4.x)/2, (point2.y + point4.y)/2);
int b = 8;
double theta = Math.toRadians(45);
GeneralPath path = new GeneralPath();
path.moveTo(0,0); // distance between line and the arrow mark
int x =(int)(-b * Math.cos(theta));
int y =(int) (b * Math.sin(theta));
path.lineTo(x,y);
x = (int) (-b * Math.cos(-theta));
y = (int) (b * Math.sin(-theta));
path.moveTo(0,0); // distance between line and the arrow mark
path.lineTo(x,y);
Shape shape = at.createTransformedShape(path);
graphics2D.setPaint(Color.black);
graphics2D.draw(shape);
at.rotate(theta,x,y);
drawLine(graphics2D,point2.x,point2.y,point4.x,poi nt4.y);// line drawing 2 points.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-17-2008, 12:22 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,029
hardwired is on a distinguished road
Code:
Point point2 = new Point(100,200); protected void paintComponent(Graphics g) { Graphics2D graphics2D = (Graphics2D)g; AffineTransform at = AffineTransform.getTranslateInstance(point2.x, point2.y); int b = 8; double theta = Math.toRadians(45); // The idea of using a GeneralPath is so we can // create the (three lines that make up the) arrow // (only) one time and then use AffineTransform to // place it anywhere we want. GeneralPath path = new GeneralPath(); // Add the arrow shaft. path.moveTo(0,0); path.lineTo(-100,0); // distance between line and the arrow mark <** not ** // Start a new line segment from the position of (0,0). path.moveTo(0,0); // Create one of the two arrow head lines. int x =(int)(-b * Math.cos(theta)); int y =(int) (b * Math.sin(theta)); path.lineTo(x,y); // distance between line and the arrow mark <** not ** // Make the other arrow head line. x = (int) (-b * Math.cos(-theta)); y = (int) (b * Math.sin(-theta)); path.moveTo(0,0); path.lineTo(x,y); // theta was used for the angle between the arrow // shaft and each of its arrow head lines. // If you wnat to also rotate the arrow (GeneralPath) // by 45 degrees, okay. // Set up the transform the way you want it, ie, do // all the work before drawing the final result. at.rotate(theta,x,y); Shape shape = at.createTransformedShape(path); graphics2D.setPaint(Color.black); graphics2D.draw(shape); // This is unnecessary since you are using the // GeneralPath to store all three lines segments // that make up the arrow, ie, the GeneralPath is // the arrow. So you apply the AffineTransform to // the GeneralPath and it does all the work. // line drawing 2 points. // graphics2D.drawLine(point2.x,point2.y,point4.x,point4.y); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mark thread RESOLVED. Eranga Suggestions & Feedback 45 04-02-2008 11:34 AM
how to draw an arrow mark using java swing sandhyau AWT / Swing 5 02-07-2008 12:52 PM
Draw an arrow Albert SWT / JFace 3 02-01-2008 09:11 AM
BufferedReader .mark(int readAheadLimit) ShoeNinja New To Java 1 11-16-2007 11:58 PM
Reading in data from file line by line bluekswing New To Java 1 10-02-2007 01:19 AM


All times are GMT +3. The time now is 01:14 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org