This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Drawing Lines by Angles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Drawing Lines by Angles" Watch "Drawing Lines by Angles" New topic
Author

Drawing Lines by Angles

Matthew Sparkes
Greenhorn

Joined: Mar 10, 2006
Posts: 2
Hi everyone, this is my first post here.

I'm writing a program at the moment, where I will have an array of ints representing angles. I will then have a series of dots connected by lines of fixed length, where the dots deviate from the upright by a certain angle.

This will allow me to plot a graph, but only storing one set of numbers.

Currently I have worked out the positions manually, and these are kept in X and Y int arrays. What I want is to be able to do something like I am currently doing with polyline, but instead using angles rather than cartesian points, but all the while keeping the seperation (line length) constant.

Any ideas?



<a href="http://non-tech-city.com/" target="_blank" rel="nofollow">Non-Tech City</a><br /><a href="http://non-tech-city.com/" target="_blank" rel="nofollow">Matthew Sparkes</a>
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
What about using the angles to generate the Cartesian points?
Matthew Sparkes
Greenhorn

Joined: Mar 10, 2006
Posts: 2
Yeah, that would be fine, but my math is a little rusty.

What sort of code would be needed if I had x,y as starts points, l as length of line, and a as angle?

I could then take this, and run through th array, adding the coordinates next to the angle, adding the coordinate of point 2 to that of point 1 and so on.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Well remember that in a right triangle, if the hypotenuse is of length l, and one of the acute angles is a, then the length of the side adjacent is l*cos(a), and the length of the side opposite it is l*sin(a). Remember that in Java, Math.sin and Math.cos expect radian values and there are pi radians in a semicircle.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Drawing Lines by Angles
 
Similar Threads
Convert image to raw binary data
Implementing PiChart
Nine dots
For the author in you
An interesting geometry question.