Re-mapping a value (Java)

From: Randy (never_at_home.com.invalid)
Date: 11/27/03


Date: Thu, 27 Nov 2003 09:13:39 GMT


I am working with some simple 3-D stuff, and have just re-written some
Visual BASIC code for Java. My re-mapping routine no longer works!, so
I am curious as to what is the best procedure for re-mapping a value
from one scale to another. In this case, the first scale is the z-value
of a coordinate within my 3-D model, typically between -5000 and 0
(-5000 to zero) [Since it's VB code, those are probably twips, not
pixels]. The second scale is 0-255 (zero to 255), for determining the
palette adjustment. I want the function to return an integer between
0-255. I am passing the minimum and maximum z values, and two points
(it works for lines, but for points, I just pass the same value twice).

Here is the method/function. I know that it is weak code:

// (Graphics object 'g' passed for debugging in applet)
static int get_RemappedRGBValue(Graphics g,
                                 int minZ,
                                 int maxZ,
                                 int p1,
                                 int p2) }

     int delta_p1_p2; // distance between the two points (z-axis)
     int range; // total possible range (for z-value)
     int remapped; // z-value, remapped to RGB scale (0-255)
     long halfwayPoint; // halfway-point (used for lines only)

   range = maxZ - minZ; // get full range for z-value

    // get distance between two points, and the halfway point
     if (p1 < p2) {
       delta_p1_p2 = p2 - p1;
       halfwayPoint = p1 + (int)(delta_p1_p2 / 2);
     }
     else { // (if [p1 > p2])
       delta_p1_p2 = p1 - p2;
       halfwayPoint = p2 + (int)(delta_p1_p2 / 2);
     }

  // calculate the new value
   remapped = (int)(((halfwayPoint - minZ) / range) * 255);

  // adjust 'brightness'
   remapped = remapped - 24;

    // fix out-of-bounds errors, if any occur
     if (remapped < 0)
         remapped = 0;

     if (remapped > 255)
         remapped = 255;

   return remapped;

} // {get_RemappedRGBValue}



Relevant Pages

  • Re: Boost process and C
    ... temperatures is nonsense, yet people do it all the time when ... zero address. ... and the same scale for the offset too. ...
    (comp.lang.c)
  • Re: In the days before DROs... Harold?
    ... lathe when I couldn't use a dro or count on using the lead screw and ... a little trough where you set a bunch of measuring rods that looked a lot like ... It had a mirrored etched glass scale attached to the table and saddle, ... could make your part's zero reference line up with a whole inch mark. ...
    (rec.crafts.metalworking)
  • Re: Zero Points?
    ... whole thing is meaningless. ... So let's call having 4.725 oranges the zero orange point. ... orange point scale then means having 5.725 oranges. ... the zero of several temperature scales. ...
    (alt.usage.english)
  • Re: In the days before DROs... Harold?
    ... lathe when I couldn't use a dro or count on using the lead screw and ... a little trough where you set a bunch of measuring rods that looked a lot like ... It had a mirrored etched glass scale attached to the table and saddle, ... could make your part's zero reference line up with a whole inch mark. ...
    (rec.crafts.metalworking)
  • Re: Help needed with multi y-axis chart
    ... Jon Peltier, Microsoft Excel MVP ... Peltier Technical Services, Inc. - http://PeltierTech.com ... the minimum value for the primary y-axis scale is less than zero. ... Other than manually tweaking the scale for the ...
    (microsoft.public.excel.charting)