List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D dotProduct
public double dotProduct(final Vector<Euclidean3D> v)
The implementation uses specific multiplication and addition algorithms to preserve accuracy and reduce cancellation effects.
From source file:com.mapr.synth.drive.DriveTest.java
static Vector3D project(Vector3D east, Vector3D north, Vector3D step) { return new Vector3D(step.dotProduct(east) * Constants.EARTH_RADIUS_KM, step.dotProduct(north) * Constants.EARTH_RADIUS_KM, 0); }
From source file:jtrace.object.Plane.java
@Override public double getFirstCollisionObjectFrame(Ray ray) { double alpha = planeNormal.dotProduct(Vector3D.ZERO.subtract(ray.origin)) / planeNormal.dotProduct(ray.direction); if (alpha < 0) return Double.POSITIVE_INFINITY; incidentRay = ray;//from ww w . j ava2 s. c o m Vector3D collisionLocation = ray.origin.add(alpha, ray.direction); normalRay = new Ray(collisionLocation, planeNormal); Vector3D q = collisionLocation; u = q.dotProduct(planeNorth); v = q.dotProduct(planeEast); return alpha; }
From source file:jtrace.Camera.java
/** * Retrieve coordinates of pixel corresponding to given point in an image * with the given width and height.// w ww .j ava 2 s .com * * @param width * @param height * @param point 3d point to project * @return double[] containing x and y coordinates of pixel. */ public int[] getPixel(int width, int height, Vector3D point) { int[] coord = new int[2]; Vector3D l = point.subtract(location); double lu = l.dotProduct(up); double lr = l.dotProduct(right); double lp = l.dotProduct(direction); coord[0] = (int) Math.round(((lr / lp) * (1.0 / fovRight) + 0.5) * width); coord[1] = (int) Math.round(((lu / lp) * (-1.0 / fovUp) + 0.5) * height); return coord; }
From source file:ch.zweivelo.renderer.simple.shapes.Sphere.java
@Override public Optional<Double> calculateIntersectionDistance(final Ray ray) { Vector3D dir = ray.getDirection(); Vector3D tmp = ray.getOrigin().subtract(center); OptionalDouble min = Solver.QUADRATIC .solve(tmp.dotProduct(tmp) - radius * radius, 2 * dir.dotProduct(tmp), dir.dotProduct(dir)).min(); if (min.isPresent()) { return Optional.of(min.getAsDouble()); }//from w w w . java2s . c o m return Optional.empty(); }
From source file:jtrace.texture.DiffuseFinish.java
@Override public Colour layerFinish(SceneObject object, Colour pigmentColour, Colour colour) { Colour diffuseColour = new Colour(0, 0, 0); Ray normalRay = object.getNormalRay(); for (LightSource light : object.getVisibleLights()) { // Determine distance to and direction of light source Vector3D lightDir = light.getLocation().subtract(normalRay.origin); double lightDistanceSq = lightDir.getNormSq(); lightDir = lightDir.normalize(); // Projection of light source direction onto surface normal: double projection = lightDir.dotProduct(normalRay.direction); if (projection > 0.0) { // Determine degree of illumination: double illum = projection * light.getIntensity(lightDistanceSq); // Scale light colour by illumination and add to diffuse colour: diffuseColour = diffuseColour.add(light.getColour().scale(illum)); }/*w ww.j av a 2s.com*/ } return colour.add(pigmentColour.filter(diffuseColour).scale(diffuse)); }
From source file:jtrace.texture.SpecularFinish.java
@Override public Colour layerFinish(SceneObject object, Colour pigmentColour, Colour colour) { Colour specularColour = new Colour(0, 0, 0); Ray incidentRay = object.getIncidentRay(); Ray normalRay = object.getNormalRay(); Ray reflectedRay = object.getReflectedRay(); for (LightSource light : object.getVisibleLights()) { // Determine distance and direction to light: Vector3D lightDir = light.getLocation().subtract(normalRay.origin); double lightDistanceSq = lightDir.getNormSq(); lightDir = lightDir.normalize(); // Projection of light direction onto reflected ray: double projection = lightDir.dotProduct(reflectedRay.direction); if (projection > 0) { // Digree of illumination: double illum = Math.pow(projection, tightness) * light.getIntensity(lightDistanceSq); // Scale light colour by intensity and add to specular colour: specularColour = specularColour.add(light.getColour().scale(illum)); }//w ww . j a va 2s . c o m } return colour.add(specularColour); }
From source file:edu.mit.fss.examples.member.OrekitSurfaceElement.java
/** * Gets the relative speed (in m/s) from this element * to the specified element./*from ww w. ja v a 2s. co m*/ * * @param element the element * @return the relative speed */ public double getRelativeSpeed(Element element) { if (element.getFrame() == ReferenceFrame.UNKNOWN) { logger.warn("Unknown reference frame for element " + element + ", cannot compute elevation."); return 0; } try { Transform t = element.getFrame().getOrekitFrame().getTransformTo(frame.getOrekitFrame(), getDate()); Vector3D relPosition = t.transformVector(element.getPosition()).subtract(getPosition()); Vector3D relVelocity = t.transformVector(element.getVelocity()).subtract(getVelocity()); // compute relative speed return relVelocity.dotProduct(relPosition.normalize()); } catch (OrekitException e) { logger.error(e.getMessage()); } return 0; }
From source file:edu.mit.fss.examples.member.OrekitOrbitalElement.java
/** * Gets the relative speed (in m/s) from this element * to the specified element.//ww w.ja v a 2s.com * * @param element the element * @return the relative speed */ public double getRelativeSpeed(Element element) { if (element.getFrame() == ReferenceFrame.UNKNOWN) { logger.warn("Unknown reference frame for element " + element + ", cannot compute elevation."); return 0; } try { Transform t = element.getFrame().getOrekitFrame().getTransformTo(getFrame().getOrekitFrame(), getDate()); Vector3D relPosition = t.transformVector(element.getPosition()).subtract(getPosition()); Vector3D relVelocity = t.transformVector(element.getVelocity()).subtract(getVelocity()); // compute relative speed return relVelocity.dotProduct(relPosition.normalize()); } catch (OrekitException e) { logger.error(e.getMessage()); } return 0; }
From source file:gentracklets.conversions.java
public static double[] geo2radec(PVCoordinates obj, TopocentricFrame staF, Frame inertialFrame, AbsoluteDate epoch) {// w w w. jav a2s . c om Vector3D rho = new Vector3D(0, 0, 0); try { rho = obj.getPosition().subtract(staF.getPVCoordinates(epoch, inertialFrame).getPosition()); } catch (OrekitException ex) { Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex); } double rho_mag = rho.getNorm(); double DEC = FastMath.asin(rho.getZ() / rho_mag); double cosRA = 0.0; double sinRA = 0.0; double RA = 0.0; Vector3D v_site = new Vector3D(0, 0, 0); try { v_site = staF.getPVCoordinates(epoch, inertialFrame).getVelocity(); } catch (OrekitException ex) { Logger.getLogger(conversions.class.getName()).log(Level.SEVERE, null, ex); } Vector3D rhoDot = obj.getVelocity().subtract(v_site); if (FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)) != 0) { cosRA = rho.getX() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)); sinRA = rho.getY() / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)); RA = FastMath.atan2(sinRA, cosRA); if (RA <= 0) { RA = RA + 2 * FastMath.PI; } } else { sinRA = rhoDot.getY() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2)); cosRA = rhoDot.getX() / FastMath.sqrt(FastMath.pow(rhoDot.getX(), 2) + FastMath.pow(rhoDot.getY(), 2)); RA = FastMath.atan2(sinRA, cosRA); if (RA <= 0) { RA = RA + 2 * FastMath.PI; } } double rhoDot_mag = rho.dotProduct(rhoDot) / rho_mag; double RAdot = (rhoDot.getX() * rho.getY() - rhoDot.getY() * rho.getX()) / (-1 * FastMath.pow(rho.getY(), 2) - FastMath.pow(rho.getX(), 2)); double DECdot = (rhoDot.getZ() - rhoDot_mag * FastMath.sin(DEC)) / FastMath.sqrt(FastMath.pow(rho.getX(), 2) + FastMath.pow(rho.getY(), 2)); double[] out = { RA, RAdot, DEC, DECdot, rho_mag, rhoDot_mag }; return out; }
From source file:org.hakkit.bounding.Ray.java
@Override public boolean intersect(BoundingSphere b) { double radiusSquared = b.getRadius() * b.getRadius(); Vector3D L = b.getCenter().subtract(getOrigin()); double tca = L.dotProduct(getDirection()); if (tca < 0) return false; //Very bad. double d2 = L.dotProduct(L) - tca * tca; if (d2 > radiusSquared) return false; double thc = Math.sqrt(radiusSquared - d2); //Distance from the origin to the center of the intersections double t0 = tca - thc; //Distance from ray origin to the intersection point double t1 = tca + thc; //Distance from the ray origin to the second intersection point //Ensure the first intersection is within our value range. if (t0 > maximum || t0 < minimum) return false; //It must be within range, and an intersection must have occurred. return true;/* w ww .j a v a 2 s.c om*/ }