1

I am looking for an open source package (preferably Java but R or other languages would be ok too) that provides these 2 functions

1) points output_seq[] SCALE(points input_seq[], double factor)

In other words a sequence of doubles (x1,y1), (x2,y2)... is given as input that represents a graph (each point is connected to the next by a straight line) and a scaling factor is given. Then it returns a similar sequence as output. The catch is that the output sequence may have fewer or more elements than the input. For example, if I request magnification by a factor of 2.012 then the output sequence may have twice as many elements as the input. The scaling factor should be a double, not an integer. Lastly, it's important to return the output sequence as points (doubles), I have very little interest in the actual drawing on a screen beyond proving that it does the right thing.

2) points output_seq[] ROTATE(points input_seq[], double angle)

same as above, except there is no scaling but just rotation, the angle is from 0 to 359.9999 and is given in radians. The size of the output is always the same as the size of the input. Again the emphasis is on getting the output sequence as doubles, not so much on the actual drawing on a screen.

If you know the right terminology I should have used then let me know. Thank you so much.

Kim Huong
  • 13
  • 2
  • 1
    so with the `SCALE` you want to for instance increase the "density" of the points? With what interpolation-technique should the extra points be generated? Linear interpolation? – aioobe Aug 21 '11 at 19:52
  • yes, I want to increase or decrease the density. Linear interpolation or other kinds would be fine, I have no preference. – Kim Huong Aug 21 '11 at 19:55
  • 2
    If you use radians, the angle goes from 0 to 6.28... Also you must specify the point around which the rotation is made. – toto2 Aug 21 '11 at 19:58
  • When you say a "graph" you just mean a sequence of line segments (one long snake)? – toto2 Aug 21 '11 at 19:59
  • 3
    I doubt you'll find a library with those particular methods. Doesn't sound too hard to write your self. How about you give it a try, and post a new question on each of the methods once you've had a stab at it? – aioobe Aug 21 '11 at 19:59
  • @toto2 yes 1 long snake is correct – Kim Huong Aug 21 '11 at 20:11
  • ok, you are right that the point of rotation must also be provided – Kim Huong Aug 21 '11 at 20:12
  • @aioobe, I am not as bright as some of you guys, that's why I was hoping to get an easy solution from someone who has faced those kinds of problems before – Kim Huong Aug 21 '11 at 20:13
  • Linear interpolation: between each pair of points you add a new point ((x_i + x_(i+1))/2, (y_i + y_(i+1))/2). But the new snake will be as jagged as before (it is identical on screen), so you probably don't want something this simple. – toto2 Aug 21 '11 at 20:15
  • @toto2 if the snake is magnified 1.1 times then linear interpolation may result in many additional points, in addition to jagged-ness. Scaling up 1.1 times should add only about 10% more points – Kim Huong Aug 21 '11 at 20:25

1 Answers1

1

In Java, Path2D is suitable for 2D floating point coordinates. The lineTo() method will add straight lines to the path. Because Path2D implements the Shape interface, rotate and scale are possible via createTransformedShape(). One approach to interpolation, using PathIterator, is shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    many thanks, let me study this solution for a couple days, then I will mark your answer appropriately. – Kim Huong Aug 22 '11 at 02:32