Results 1 to 6 of 6
  1. #1
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

    Default looking for Point interpolater

    Hello,

    I'm wondering if there's a method or class or algorithm of some kind in the Java APIs that will take in two Point objects and interpolate them.

    More specifically, I'd like something that will help me produce a line between the points, but I need this line to be made up of Points itself - that is, an array or vector (or something like that) of Points, one per pixel.

    If there's something in the Java APIs that can do just that, that would be perfect, but even something that help (like an interpolater) would do the trick. By an 'interpolater' I mean something that takes in two points and a weight and gives back an interpolated Point according to the weight passed into it. The weight would be an int (or double) indicating how close to the one point (and how far away from the other Point) the resulting point is to be. For example, say I passed in .8 for my weight (or 80 if its an int - to be interpreted as 80%), then it would give me the Point that's 80% the way from the first Point to the second Point.

    Is there anything like this in the Java APIs or even anything that will help me accomplish what I want to do? Is there any online algorithm outside the Java Platform site that shows how to do this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Given point (x1, y1) and point (x2, y2) all points on the line segment between those two points can be described as (x1, y1)+p*(x2-x1, y2-y1). So for p= 0.8 you have your answer.

    kind regards,

    Jos

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    array or vector (or something like that) of Points, one per pixel.
    Do you want just the Points for pixels the line actually goes thru? Since pixel positions are whole numbers, the line could go between some pixels.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Norm View Post
    Do you want just the Points for pixels the line actually goes thru? Since pixel positions are whole numbers, the line could go between some pixels.
    That doesn't matter; the Bresenham line drawing algorithm hits those pixels that are nearest to the ideal line so my method (see previous reply) gives the top left corner of a pixel on a Bresenham line after truncating to ints.

    kind regards,

    Jos
    Last edited by JosAH; 08-20-2010 at 04:21 PM.

  6. #6
    gib65 is offline Member
    Join Date
    Jun 2010
    Posts
    86
    Rep Power
    0

    Default

    Thanks everyone,

    If the formula is as simple as that, I will write my own method.

Similar Threads

  1. Access Point
    By ja107 in forum Networking
    Replies: 0
    Last Post: 03-05-2010, 05:59 PM
  2. Drawing a point
    By chappa in forum AWT / Swing
    Replies: 3
    Last Post: 12-13-2009, 08:24 PM
  3. Can someone point me to an example?
    By smhjr in forum New To Java
    Replies: 2
    Last Post: 08-27-2009, 11:38 PM
  4. is it bug? or am i missing a point?
    By blowguy in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-20-2007, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •