com.ajc.esim.core
Class Calc

java.lang.Object
  extended by com.ajc.esim.core.Calc

public final class Calc
extends java.lang.Object


Field Summary
static double grain
          grain is the line length for drawing field lines, decreasing it does not improve resolution, the current value is the best one I have found.
static double k
          Coulomb's constant k
 
Constructor Summary
Calc()
           
 
Method Summary
static double[] calcEF(int x, int y)
          Calculates the electric field and electric potential for a point.
static double cLaw(double charge, double radius)
          Coulomb's law calculator
static double dist(double x1, double y1, double x2, double y2)
          Pythagorean Therom - Calculates the distance between two points: (x1,y1) and (x2,y2).
static java.util.ArrayList<CPoint> drawFieldLine(int x, int y)
          Draws a curve representing the electric field line of a group of charge(s).
static void drawLines(java.util.ArrayList<CPoint> pts, java.awt.Graphics2D g)
           
static void drawPELine(double val, java.awt.Graphics2D g1)
          Draws a 'line'(thin graident) where the points on that line all have the same electric potential
static Prefix findPrefix(double val)
          Gets the best prefix for a number.
static boolean plus_minus(double val, double target, double plusminus)
          Determines if a value is with in a range of a target value
static double potential(double charge, double radius)
          Potential enegry formula
static double totalForce(int x, int y)
          Calculates the magnitude of the force (in Newtons) exerted at a point using Pythagoras' Theorem.
static double[] totalForce2(int x, int y)
          Returns an array containing the X force, Y Force and Total Force
static double[] totalForceAngle(int x, int y)
          Returns the total force and angle.
static double totalPE(int x, int y)
          Total potential enegery at a point.
static java.lang.String toTruncString(double val, int places)
          Returns a string representation of a number truncated to a specificed number of places
static double truncate(double val, int deci)
          Truncates a number to the specificed number of decimal places
static java.awt.Color valuGrad(double min, double max, double val)
          Calculates color based on the input value's location in the range
static java.awt.Color valuGradBW(double min, double max, double val)
          Modified version of valuGrad for the drawPELine method.
static double vectorAngle(int x, int y)
          Calculates the angle clockwise from verticle that the force points
static double xForce(int x, int y)
          Calculates the horizontal force exerted by all the charges at a given point
static double yForce(int x, int y)
          Calculates the verticle force exerted by all the charges at a given point
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

grain

public static final double grain
grain is the line length for drawing field lines, decreasing it does not improve resolution, the current value is the best one I have found.

See Also:
Constant Field Values

k

public static final double k
Coulomb's constant k

See Also:
Constant Field Values
Constructor Detail

Calc

public Calc()
Method Detail

calcEF

public static double[] calcEF(int x,
                              int y)
Calculates the electric field and electric potential for a point.

Parameters:
x - X Location (in pixels)
y - Y Location (in pixels)
Returns:
Array with two values, first value "[0]" is the potential enegry at point (x,y). The second value "[1]" is the electric field at the point (x,y).

cLaw

public static double cLaw(double charge,
                          double radius)
Coulomb's law calculator

Parameters:
charge - PointCharge with which to calculate the charge
radius - Distance from the charge(in pixels) to calculate the force at.
Returns:
double, force in Newtons exerted by the charge

dist

public static double dist(double x1,
                          double y1,
                          double x2,
                          double y2)
Pythagorean Therom - Calculates the distance between two points: (x1,y1) and (x2,y2).

Parameters:
x1 - X Location of first element
y1 - Y Location of first element
x2 - X Location of second element
y2 - Y Location of second element
Returns:
distance between two points

drawFieldLine

public static java.util.ArrayList<CPoint> drawFieldLine(int x,
                                                        int y)
Draws a curve representing the electric field line of a group of charge(s). Delegates calculations to totalForce. The method draws a line from point c (the starting point) to point n, with n being the grain the percentage of the force up/down, left/right the color of the line segment is calculated by valuGrad the loop stops if line is outside of a fixed window (-1600 to 1600 pixels).

Parameters:
x - X location to begin drawing
y - Y location to begin drawing
g - Graphics2D used to draw
See Also:
valuGrad(double, double, double), totalForce2(int, int)

drawLines

public static void drawLines(java.util.ArrayList<CPoint> pts,
                             java.awt.Graphics2D g)

drawPELine

public static void drawPELine(double val,
                              java.awt.Graphics2D g1)
Draws a 'line'(thin graident) where the points on that line all have the same electric potential

Parameters:
val - Potential at which to draw the line
g1 - Graphics2D with which to paint

findPrefix

public static Prefix findPrefix(double val)
Gets the best prefix for a number.

Parameters:
val - number to look for a prefix for
Returns:
Prefix
See Also:
Data.getPrefix(int)

plus_minus

public static boolean plus_minus(double val,
                                 double target,
                                 double plusminus)
Determines if a value is with in a range of a target value

Parameters:
val - value to check
target - target value
plusminus - 'error term' maximum absloute distance from the target value.
Returns:
true if val is within the error term for the targe value, false otherwise.

potential

public static double potential(double charge,
                               double radius)
Potential enegry formula

Parameters:
charge - double, charge (in Coulombs)
radius - double, distance from charge to calculate PE at
Returns:
double, Voltage at a given distance from a charge.

totalForce

public static double totalForce(int x,
                                int y)
Calculates the magnitude of the force (in Newtons) exerted at a point using Pythagoras' Theorem.

Parameters:
x - X Location to calculate the force at.
y - Y Location to calculate the force at.
Returns:
double, force at point (x,y)

totalForce2

public static double[] totalForce2(int x,
                                   int y)
Returns an array containing the X force, Y Force and Total Force

Parameters:
x - X Location
y - Y Location
Returns:
double array, value 0 is the total force, value 1 is the x force and value 2 is the y force

totalForceAngle

public static double[] totalForceAngle(int x,
                                       int y)
Returns the total force and angle.

Parameters:
x - X Location
y - Y Location
Returns:
double array value 0 is the total force, value 1 is the angle (in degrees)

totalPE

public static double totalPE(int x,
                             int y)
Total potential enegery at a point.

Parameters:
x - X Location
y - Y Location
Returns:
double, total potential enegry at point (x,y)

toTruncString

public static java.lang.String toTruncString(double val,
                                             int places)
Returns a string representation of a number truncated to a specificed number of places

Parameters:
val - Number to truncate
places - Number of places to keep
Returns:
String
See Also:
truncate(double, int)

truncate

public static double truncate(double val,
                              int deci)
Truncates a number to the specificed number of decimal places

Parameters:
val - Number to be truncated
deci - Number of decimal places to be kept
Returns:
double, truncated to deci number of decimal places

valuGrad

public static java.awt.Color valuGrad(double min,
                                      double max,
                                      double val)
Calculates color based on the input value's location in the range

Parameters:
min - minimum value of range
max - maximum value of range
val - value to find color for
Returns:
java.awt.Color

valuGradBW

public static java.awt.Color valuGradBW(double min,
                                        double max,
                                        double val)
Modified version of valuGrad for the drawPELine method. Returns an alpha gradient using the potential color.

Parameters:
min - Minimum value, if val==min, alpha value is 0: Color is transparent.
max - Maximum value, if val==max alpha value is 255: Color is fully opaque.
val - value, must between min and max or color returned will be null!
Returns:
java.awt.Color, same color as Launcher.dat.potentialColor, alpha value equal to val as a percentage of max.

vectorAngle

public static double vectorAngle(int x,
                                 int y)
Calculates the angle clockwise from verticle that the force points

Parameters:
x - X location to determine the angle
y - Y location to determine the angle
Returns:
degrees

xForce

public static double xForce(int x,
                            int y)
Calculates the horizontal force exerted by all the charges at a given point

Parameters:
x - X Location to calculate the force at
y - Y Location to calculate the force at
Returns:
Force in Newtons

yForce

public static double yForce(int x,
                            int y)
Calculates the verticle force exerted by all the charges at a given point

Parameters:
x - X Location to calculate the force at
y - Y Location to calculate the force at
Returns:
Force in Newtons