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.

What about using the angles to generate the Cartesian points?

Matthew Sparkes
Greenhorn

Joined: Mar 10, 2006
Posts: 2

posted

0

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

posted

0

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.

Don't get me started about those stupid light bulbs.