Re-mapping a value (Java)
From: Randy (never_at_home.com.invalid)
Date: 11/27/03
- Next message: Jonas Mellin: "Re: Choosing a DataStructure"
- Previous message: Corey Murtagh: "Re: fonts for use in c or c++ program"
- Next in thread: Leif Roar Moldskred: "Re: Re-mapping a value (Java)"
- Reply: Leif Roar Moldskred: "Re: Re-mapping a value (Java)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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}
- Next message: Jonas Mellin: "Re: Choosing a DataStructure"
- Previous message: Corey Murtagh: "Re: fonts for use in c or c++ program"
- Next in thread: Leif Roar Moldskred: "Re: Re-mapping a value (Java)"
- Reply: Leif Roar Moldskred: "Re: Re-mapping a value (Java)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|