List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D getNormSq
public double getNormSq()
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)); }//from w w w. ja va 2s . c o m } 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)); }//from w w w . java2s . com } return colour.add(specularColour); }
From source file:jtrace.object.Sphere.java
@Override public double getFirstCollisionObjectFrame(Ray ray) { Vector3D displacement = ray.getOrigin(); double a = ray.getDirection().getNormSq(); double b = 2.0 * ray.getDirection().dotProduct(displacement); double c = displacement.getNormSq() - 1.0; // Check for miss: if (b * b < 4.0 * a * c) return Double.POSITIVE_INFINITY; // Determine actual intersections double alpha0 = -0.5 * b / a; double dalpha = 0.5 * Math.sqrt(b * b - 4.0 * a * c) / a; double alphaPlus = alpha0 + dalpha; double alphaMinus = alpha0 - dalpha; // Abort if no intersections in front of us if (alphaMinus < 0 && alphaPlus < 0) return Double.POSITIVE_INFINITY; // Find closest intersection in front of us double alpha; if (alphaMinus < alphaPlus && alphaMinus > 0) alpha = alphaMinus;//w w w . j a v a 2 s. c o m else alpha = alphaPlus; // Record incident and normal rays incidentRay = ray; Vector3D collisionLocation = ray.direction.scalarMultiply(alpha).add(ray.origin); Vector3D normal = collisionLocation.normalize(); normalRay = new Ray(collisionLocation, normal); return alpha; }
From source file:org.orekit.attitudes.CelestialBodyPointed.java
/** {@inheritDoc} */ public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) throws OrekitException { final PVCoordinates satPV = pvProv.getPVCoordinates(date, celestialFrame); // compute celestial references at the specified date final PVCoordinates bodyPV = pointedBody.getPVCoordinates(date, celestialFrame); final PVCoordinates pointing = new PVCoordinates(satPV, bodyPV); final Vector3D pointingP = pointing.getPosition(); final double r2 = Vector3D.dotProduct(pointingP, pointingP); // evaluate instant rotation axis due to sat and body motion only (no phasing yet) final Vector3D rotAxisCel = new Vector3D(1 / r2, Vector3D.crossProduct(pointingP, pointing.getVelocity())); // fix instant rotation to take phasing constraint into account // (adding a rotation around pointing axis ensuring the motion of the phasing axis // is constrained in the pointing-phasing plane) final Vector3D v1 = Vector3D.crossProduct(rotAxisCel, phasingCel); final Vector3D v2 = Vector3D.crossProduct(pointingP, phasingCel); final double compensation = -Vector3D.dotProduct(v1, v2) / v2.getNormSq(); final Vector3D phasedRotAxisCel = new Vector3D(1.0, rotAxisCel, compensation, pointingP); // compute transform from celestial frame to satellite frame final Rotation celToSatRotation = new Rotation(pointingP, phasingCel, pointingSat, phasingSat); // build transform combining rotation and instant rotation axis Transform transform = new Transform(date, celToSatRotation, celToSatRotation.applyTo(phasedRotAxisCel)); if (frame != celestialFrame) { // prepend transform from specified frame to celestial frame transform = new Transform(date, frame.getTransformTo(celestialFrame, date), transform); }// w ww.j av a2 s. c o m // build the attitude return new Attitude(date, frame, transform.getRotation(), transform.getRotationRate(), transform.getRotationAcceleration()); }
From source file:org.orekit.attitudes.GroundPointing.java
/** {@inheritDoc} */ public Attitude getAttitude(final PVCoordinatesProvider pvProv, final AbsoluteDate date, final Frame frame) throws OrekitException { // satellite-target relative vector final PVCoordinates pva = pvProv.getPVCoordinates(date, inertialFrame); final TimeStampedPVCoordinates delta = new TimeStampedPVCoordinates(date, pva, getTargetPV(pvProv, date, inertialFrame)); // spacecraft and target should be away from each other to define a pointing direction if (delta.getPosition().getNorm() == 0.0) { throw new OrekitException(OrekitMessages.SATELLITE_COLLIDED_WITH_TARGET); }// w w w . jav a 2 s . c o m // attitude definition: // line of sight -> +z satellite axis, // orbital velocity -> (z, +x) half plane final Vector3D p = pva.getPosition(); final Vector3D v = pva.getVelocity(); final Vector3D a = pva.getAcceleration(); final double r2 = p.getNormSq(); final double r = FastMath.sqrt(r2); final Vector3D keplerianJerk = new Vector3D(-3 * Vector3D.dotProduct(p, v) / r2, a, -a.getNorm() / r, v); final PVCoordinates velocity = new PVCoordinates(v, a, keplerianJerk); final PVCoordinates los = delta.normalize(); final PVCoordinates normal = PVCoordinates.crossProduct(delta, velocity).normalize(); AngularCoordinates ac = new AngularCoordinates(los, normal, PLUS_K, PLUS_J, 1.0e-9); if (frame != inertialFrame) { // prepend transform from specified frame to inertial frame ac = ac.addOffset(frame.getTransformTo(inertialFrame, date).getAngular()); } // build the attitude return new Attitude(date, frame, ac); }
From source file:org.orekit.forces.BoxAndSolarArraySpacecraft.java
/** {@inheritDoc} */ public Vector3D radiationPressureAcceleration(final AbsoluteDate date, final Frame frame, final Vector3D position, final Rotation rotation, final double mass, final Vector3D flux) throws OrekitException { if (flux.getNormSq() < Precision.SAFE_MIN) { // null illumination (we are probably in umbra) return Vector3D.ZERO; }/*from w w w . ja v a 2 s . com*/ // radiation flux in spacecraft frame final Vector3D fluxSat = rotation.applyTo(flux); // solar array contribution Vector3D normal = getNormal(date, frame, position, rotation); double dot = Vector3D.dotProduct(normal, fluxSat); if (dot > 0) { // the solar array is illuminated backward, // fix signs to compute contribution correctly dot = -dot; normal = normal.negate(); } Vector3D force = facetRadiationAcceleration(normal, solarArrayArea, fluxSat, dot); // body facets contribution for (final Facet bodyFacet : facets) { normal = bodyFacet.getNormal(); dot = Vector3D.dotProduct(normal, fluxSat); if (dot < 0) { // the facet intercepts the incoming flux force = force.add(facetRadiationAcceleration(normal, bodyFacet.getArea(), fluxSat, dot)); } } // convert to inertial frame return rotation.applyInverseTo(new Vector3D(1.0 / mass, force)); }
From source file:org.orekit.forces.BoxAndSolarArraySpacecraft.java
/** {@inheritDoc} */ public FieldVector3D<DerivativeStructure> radiationPressureAcceleration(final AbsoluteDate date, final Frame frame, final Vector3D position, final Rotation rotation, final double mass, final Vector3D flux, final String paramName) throws OrekitException { if (flux.getNormSq() < Precision.SAFE_MIN) { // null illumination (we are probably in umbra) final DerivativeStructure zero = new DerivativeStructure(1, 1, 0.0); return new FieldVector3D<DerivativeStructure>(zero, zero, zero); }//from w w w . j a va 2 s. c o m final DerivativeStructure absorptionCoeffDS; final DerivativeStructure specularReflectionCoeffDS; if (ABSORPTION_COEFFICIENT.equals(paramName)) { absorptionCoeffDS = new DerivativeStructure(1, 1, 0, absorptionCoeff); specularReflectionCoeffDS = new DerivativeStructure(1, 1, specularReflectionCoeff); } else if (REFLECTION_COEFFICIENT.equals(paramName)) { absorptionCoeffDS = new DerivativeStructure(1, 1, absorptionCoeff); specularReflectionCoeffDS = new DerivativeStructure(1, 1, 0, specularReflectionCoeff); } else { throw new OrekitException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, paramName, ABSORPTION_COEFFICIENT + ", " + REFLECTION_COEFFICIENT); } final DerivativeStructure diffuseReflectionCoeffDS = absorptionCoeffDS.add(specularReflectionCoeffDS) .subtract(1).negate(); // radiation flux in spacecraft frame final Vector3D fluxSat = rotation.applyTo(flux); // solar array contribution Vector3D normal = getNormal(date, frame, position, rotation); double dot = Vector3D.dotProduct(normal, fluxSat); if (dot > 0) { // the solar array is illuminated backward, // fix signs to compute contribution correctly dot = -dot; normal = normal.negate(); } FieldVector3D<DerivativeStructure> force = facetRadiationAcceleration(normal, solarArrayArea, fluxSat, dot, specularReflectionCoeffDS, diffuseReflectionCoeffDS); // body facets contribution for (final Facet bodyFacet : facets) { normal = bodyFacet.getNormal(); dot = Vector3D.dotProduct(normal, fluxSat); if (dot < 0) { // the facet intercepts the incoming flux force = force.add(facetRadiationAcceleration(normal, bodyFacet.getArea(), fluxSat, dot, specularReflectionCoeffDS, diffuseReflectionCoeffDS)); } } // convert to inertial return FieldRotation.applyInverseTo(rotation, new FieldVector3D<DerivativeStructure>(1.0 / mass, force)); }
From source file:org.orekit.forces.gravity.NewtonianAttraction.java
/** {@inheritDoc} */ public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s, final String paramName) throws OrekitException { complainIfNotSupported(paramName);/*w w w . j ava 2 s. c o m*/ final Vector3D position = s.getPVCoordinates().getPosition(); final double r2 = position.getNormSq(); final DerivativeStructure muds = new DerivativeStructure(1, 1, 0, mu); return new FieldVector3D<DerivativeStructure>(muds.divide(-r2 * FastMath.sqrt(r2)), position); }
From source file:org.orekit.forces.gravity.Relativity.java
@Override public void addContribution(final SpacecraftState s, final TimeDerivativesEquations adder) throws OrekitException { final PVCoordinates pv = s.getPVCoordinates(); final Vector3D p = pv.getPosition(); final Vector3D v = pv.getVelocity(); //radius//from w ww . jav a 2 s .c om final double r2 = p.getNormSq(); final double r = FastMath.sqrt(r2); //speed final double s2 = v.getNormSq(); final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT; //eq. 3.146 final Vector3D accel = new Vector3D(4 * this.gm / r - s2, p, 4 * p.dotProduct(v), v) .scalarMultiply(this.gm / (r2 * r * c2)); adder.addAcceleration(accel, s.getFrame()); }
From source file:org.orekit.forces.gravity.Relativity.java
@Override public FieldVector3D<DerivativeStructure> accelerationDerivatives(final SpacecraftState s, final String paramName) throws OrekitException { complainIfNotSupported(paramName);/*from w ww . ja v a2 s. c o m*/ final DerivativeStructure gmDS = new DerivativeStructure(1, 1, 0, this.gm); final PVCoordinates pv = s.getPVCoordinates(); final Vector3D p = pv.getPosition(); final Vector3D v = pv.getVelocity(); //radius final double r2 = p.getNormSq(); final double r = FastMath.sqrt(r2); //speed final double s2 = v.getNormSq(); final double c2 = Constants.SPEED_OF_LIGHT * Constants.SPEED_OF_LIGHT; //eq. 3.146 return new FieldVector3D<DerivativeStructure>(gmDS.multiply(4 / r).subtract(s2), p, new DerivativeStructure(1, 1, 4 * p.dotProduct(v)), v).scalarMultiply(gmDS.divide(r2 * r * c2)); }