Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing Lines by Angles

 
Matthew Sparkes
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about using the angles to generate the Cartesian points?
 
Matthew Sparkes
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic