Changeset 2164


Ignore:
Timestamp:
01/26/07 13:32:44 (13 years ago)
Author:
sorber
Message:

Added method to convert from domain to pixel coordinates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/util/DisplayUtil.java

    r1746 r2164  
    2727import java.awt.event.InputEvent; 
    2828import java.awt.event.KeyEvent; 
     29import java.awt.Dimension; 
    2930import java.rmi.RemoteException; 
    3031import java.util.Hashtable; 
     
    450451  } 
    451452 
     453  /** Converts the given domain coordinates to pixel coordinates */ 
     454  public static double[] domainToPixel(DisplayImpl d, double x, double y) { 
     455    double[] v = {x, y}; 
     456 
     457    Dimension dim = d.getComponent().getSize(); 
     458     
     459    double[] a, b, c, aa, bb, cc; 
     460    aa = pixelToDomain(d, 0, 0); 
     461    bb = pixelToDomain(d, dim.width, 0); 
     462    cc = pixelToDomain(d, 0, dim.height); 
     463 
     464    a = new double[] {aa[0], aa[1]}; // pixel to domain returns a double[] of 
     465    b = new double[] {bb[0], bb[1]}; // length 3 
     466    c = new double[] {cc[0], cc[1]}; 
     467 
     468    double[] xx, yy; 
     469    xx = MathUtil.getProjection(a, b, v, false); 
     470    yy = MathUtil.getProjection(a, c, v, false); 
     471     
     472    double xb, yb; 
     473    xb = MathUtil.getDistance (a, xx); 
     474    yb = MathUtil.getDistance (a, yy); 
     475 
     476    double wb, hb; 
     477    wb = MathUtil.getDistance (a, b); 
     478    hb = MathUtil.getDistance (a, c); 
     479 
     480    double dpx, dpy; 
     481    dpx =  (dim.width * xb / wb); 
     482    dpy =  (dim.height * yb / hb); 
     483 
     484    return new double[] {dpx, dpy}; 
     485  } 
    452486} 
Note: See TracChangeset for help on using the changeset viewer.