Results 1 to 4 of 4

Thread: Line Projection

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Line Projection

    PROBLEMS: Projecting off screen date values for charting.

    BACKGROUND

    I have a charting application that uses date values on the X axis.
    For our purposes say dates are charted every 5 pixels.

    When charting, a date group (time-N to time-N+some date) is obtained, loaded from the DB into an array and the chart is made using the array values to chart that time frame . All well and good.

    The user may also draw a line on the chart. Line endpoints are snapped (correlated) to the date in order to keep the line in date position when scrolling.

    If the user scrolls the chart off screen -- the line endpoint (date) is outside the array used for charting -- and the line disappears or shows up incorrectly.

    The line endpoints (date,y) are stored in the DB so getting the original date is NOT a problem.

    Using y = mx+b will allow a line to be projected.

    QUESTION:

    1. Since the array is a fixed period (say Jan 1,2004 - May 1, 2004)
    and my beginning line endpoint is now (Nov 1, 2003), how do I get screen values for the array subscripts (screen x = 0, y = ?) so that this endpoint can be used to show the line on screen???

    Thanks
    David

  2. #2
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    I might be misunderstanding, but:

    Take a look at your line in terms of its endpoints. You could see that we have two values that we could derive from this: change in time (or x) and change in your dependent variable (your y). So from this, you could see that you have a slope (m).

    Now it is just a simple matter of putting it in your formula:

    y = mx + b.

    Hope this helps.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166
    Thanks for responding.

    y (y value) = m (slope) * x(x value) + b (y intercept)


    I need to be solving for b.

    x can be computed by taking the x (date) at .ScaleLeft and
    subracting the date diff in pixels.
    x will definitely be negative.

    y also can be computed similiarly depending on the offset from the top and bottom. y will be positive or negative.


    ----> Getting the angle for m is the problem. I believe trig can do it (don't recall if it is opp/adj but will double check) but not sure how to handle the negative x and/or y values. I would think the x or y OFF screen difference needs to be absolute and added to the x or y ON screen values , as the triangle would be larger if any value is off screen.

    Any ideas

    David

  4. #4
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    If you are just looking at the change in distance then just do:

    x(change) = x(final) - x(initial)

    to get the angle of the slope, do:

    arctan( y(change) / x(change) ), x(change) <> 0

    solving for b would be:

    b = y - mx
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

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



Click Here to Expand Forum to Full Width