Header.HeaderData selectBody(string name) { for (int i = 0; i < this.header.numBodies; i++) { Header.HeaderData body = this.header.getBodyInfo(i); if (name.Equals(body.getName())) { return(this.header.getBodyInfo(i)); } } throw new KeyNotFoundException("No body by the name " + name); }
public Coordinate[] calculatePos(Body body, double jd) { File ephFile = selectFile(jd); File.Block ephBlock = ephFile.getBlock(jd); Header.HeaderData bodyInfo = selectBody(body.getName()); //this function gets the start and end times of the relevant block double[] tRange = ephBlock.position(new int[2] { 0, 1 }); //then it scales our given time to a range the Chebyshev polynomials can accept and tells us which set to take double[] scaledTime = scaler(jd, tRange[0], tRange[1], bodyInfo.getNumCoordinates()); //so the range we need to take is: [startpos-1+numCoefs*dimension*set, numCoefs*dimension] double[] coefs = ephBlock.position(bodyInfo.getStart() - 1 + bodyInfo.getNumCoefficients() * ephFile.dimension * (int)scaledTime[0], bodyInfo.getNumCoefficients() * ephFile.dimension); double[] position = Chebyshev.sequence(coefs, scaledTime[1], ephFile.dimension); double[] velocity = Chebyshev.Dsequence(coefs, scaledTime[1], ephFile.dimension); return(new Coordinate[2] { new Coordinate(position), new Coordinate(velocity) }); }