JClass 4.5.0 API
Documentation

com.klg.jclass.swing.gauge
Class GaugeUtil

java.lang.Object
  |
  +--com.klg.jclass.swing.gauge.GaugeUtil

public class GaugeUtil
extends Object

This class contains common methods for performing linear transformations.


Constructor Summary
GaugeUtil()
           
 
Method Summary
static double angleToValue(double angle, double startValue, double stopValue, double startAngle, double stopAngle)
          Given an angle, returns the closest scale value.
static double arcAngle(double startAngle, double stopAngle)
          Java uses the notion of startAngle and arcAngle to draw arcs, so this method returns the arcAngle from startAngle and stopAngle.
static double distanceBetweenAngles(double a1, double a2)
          Returns the difference of two angles.
static double fromRadians(double radians)
          Converts radians to degrees.
static Rectangle getExtrema(Polygon p)
          Returns a Rectangle, where x = min_x, y = min_y, width = max_x and height = max_y.
static double normalizeAngle(double angle)
          Returns the angle between 0° and 360° corresponding to the inputted angle
static double pointToAngle(double x, double y, double x_orig, double y_orig)
          Returns an angle given a point and the origin.
static Polygon rotate(Polygon p, double degrees)
          2D rotation of points.
static Polygon scale(Polygon p, double xAmount, double yAmount)
          Scales an object.
static double toRadians(double degrees)
          Converts degrees to radians.
static Polygon translate(Polygon p, int xamount, int yamount)
          Translate a 2D polygon.
static double valueToAngle(double value, double start_value, double stop_value, double start_angle, double stop_angle)
          Converts a double value to an angle in degrees.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GaugeUtil

public GaugeUtil()
Method Detail

valueToAngle

public static double valueToAngle(double value,
                                  double start_value,
                                  double stop_value,
                                  double start_angle,
                                  double stop_angle)
Converts a double value to an angle in degrees. start_value and stop_value are the min and max values for the range. start_angle and stop_angle are the starting and stopping angle for the range.
Parameters:
value -  
start_value -  
stop_value -  
start_angle -  
stop_angle -  

pointToAngle

public static double pointToAngle(double x,
                                  double y,
                                  double x_orig,
                                  double y_orig)
Returns an angle given a point and the origin.
Parameters:
x -  
y -  
x_orig -  
y_orig -  

angleToValue

public static double angleToValue(double angle,
                                  double startValue,
                                  double stopValue,
                                  double startAngle,
                                  double stopAngle)
Given an angle, returns the closest scale value.
Parameters:
angle - An angle
startValue - The circular scale's start value
stopValue - The circular scale's stop value
startAngle - The circular scale's start angle
stopAngle - The circular scale's stop angle
Returns:
The closest scale value corresponding to the given angle

distanceBetweenAngles

public static double distanceBetweenAngles(double a1,
                                           double a2)
Returns the difference of two angles.
Parameters:
a1 - An angle
a2 - An angle
Returns:
The difference of the two angles

arcAngle

public static double arcAngle(double startAngle,
                              double stopAngle)
Java uses the notion of startAngle and arcAngle to draw arcs, so this method returns the arcAngle from startAngle and stopAngle.
Parameters:
startAngle -  
stopAngle -  

normalizeAngle

public static double normalizeAngle(double angle)
Returns the angle between 0° and 360° corresponding to the inputted angle
Parameters:
angle - Any angle
Returns:
An angle between 0° and 360°

toRadians

public static double toRadians(double degrees)
Converts degrees to radians.
Parameters:
degrees -  
Returns:
The input angle converted to radians

fromRadians

public static double fromRadians(double radians)
Converts radians to degrees.
Parameters:
radians - The radians to be converted to degrees
Returns:
The input angle converted to degrees

getExtrema

public static Rectangle getExtrema(Polygon p)
Returns a Rectangle, where x = min_x, y = min_y, width = max_x and height = max_y.
Parameters:
p - The input polygon
Returns:
The the upper left and lower right corners of the input polygon

scale

public static Polygon scale(Polygon p,
                            double xAmount,
                            double yAmount)
Scales an object. Amounts greater than one increase its size, amounts less than one decrease its size.
Parameters:
p - the input polygon
xAmount - the amount by which the width is to be scaled
yAmount - the amount by which the height is to be scaled
Returns:
A new, scaled polygon

rotate

public static Polygon rotate(Polygon p,
                             double degrees)
2D rotation of points.
Parameters:
p - The input polygon
degrees - The number of degrees to rotate this polygon
Returns:
A new, rotated polygon

translate

public static Polygon translate(Polygon p,
                                int xamount,
                                int yamount)
Translate a 2D polygon.
Parameters:
p - The input polygon
xamount - The amount by which the polygon will be shifted horizontally
yamount - The amount by which the polygon will be shifted vertically
Returns:
a new, translated polygon

Copyright© 1999-2000 KL Group Inc.
All rights reserved.