File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Draw a curve in Java if only have 3 coordinates known.....Help !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Draw a curve in Java if only have 3 coordinates known.....Help !!" Watch "Draw a curve in Java if only have 3 coordinates known.....Help !!" New topic
Author

Draw a curve in Java if only have 3 coordinates known.....Help !!

motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
How can i draw a curve in java language ?
The figure show the curve i going to draw ....if i have coordinate, then how to draw the curve,
and i also need to draw the curve and link it to become a circle if i only have 3 coordinates as shown,
the other may need to do estimation to draw it.
Anyone have the best way to do so ?



[Thumbnail for Untitled-1.jpg]

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Recommended reading http://java.sun.com/docs/books/tutorial/uiswing/painting/
Graphics#drawArc() is your friend


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

I think that Graphics.drawArc can help you draw that line, but you will probably need to transform your coordinates a bit. That's where basic math comes in, with sin, cos and tan (which are all available in the Math class).

Consider this little example:
The rectangle is to indicate how the x, y width and height values work. As you see, they form a rectangle all around the oval (end angle == 360). Now all you need to do is take these three coordinates and calculate x, y, width, height, the start angle and the end angle (0 and 60 respectively in my example).

Here's a hint:
- calculate the angle between (x,y) and (x1,y1) using Math
- calculate the angle between (x,y) and (x2,y2) using Math
- calculate x3 for which (x3,y) would be on the oval, using Math
- calculate y3 for which (x,y3) would be on the oval, using Math
- calculate the width and x position for the arc using x and x3
- calculate the height and y position for the arc using y and y3
- draw the arc!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
Rob Prime wrote:I think that Graphics.drawArc can help you draw that line, but you will probably need to transform your coordinates a bit. That's where basic math comes in, with sin, cos and tan (which are all available in the Math class).


Thankyou so much ....I will go thru it...
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
Maneesh Godbole wrote:Recommended reading http://java.sun.com/docs/books/tutorial/uiswing/painting/
Graphics#drawArc() is your friend


Thanks ....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

motress zlting wrote:thru

Sorry to nitpick but please UseRealWords: through, not thru.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

You might want to look at this too:
How to plot curves


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Draw a curve in Java if only have 3 coordinates known.....Help !!
 
Similar Threads
Draw a cloud
'Moving' a circle along a line
Beizer curve with three points?
Converting a two dimensional int array into a byte array
How to reset jpanel...