ext.plantuml.com.ctreber.acearth.projection.Projection Maven / Gradle / Ivy
Show all versions of plantuml-gplv2 Show documentation
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
/* +=======================================================================
* |
* | PlantUML : a free UML diagram generator
* |
* +=======================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/liberapay (only 1€ per month!)
* https://plantuml.com/paypal
*
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License V2.
*
* THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
* LICENSE ("AGREEMENT"). [GNU General Public License V2]
*
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
*
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PlantUML can occasionally display sponsored or advertising messages. Those
* messages are usually generated on welcome or error images and never on
* functional diagrams.
* See https://plantuml.com/professional if you want to remove them
*
* Images (whatever their format : PNG, SVG, EPS...) generated by running PlantUML
* are owned by the author of their corresponding sources code (that is, their
* textual description in PlantUML language). Those images are not covered by
* this GPL v2 license.
*
* The generated images can then be used without any reference to the GPL v2 license.
* It is not even necessary to stipulate that they have been generated with PlantUML,
* although this will be appreciated by the PlantUML team.
*
* There is an exception : if the textual description in PlantUML language is also covered
* by any license, then the generated images are logically covered
* by the very same license.
*
* This is the IGY distribution (Install GraphViz by Yourself).
* You have to install GraphViz and to setup the GRAPHVIZ_DOT environment variable
* (see https://plantuml.com/graphviz-dot )
*
* Icons provided by OpenIconic : https://useiconic.com/open
* Archimate sprites provided by Archi : http://www.archimatetool.com
* Stdlib AWS provided by https://github.com/milo-minderbinder/AWS-PlantUML
* Stdlib Icons provided https://github.com/tupadr3/plantuml-icon-font-sprites
* ASCIIMathML (c) Peter Jipsen http://www.chapman.edu/~jipsen
* ASCIIMathML (c) David Lippman http://www.pierce.ctc.edu/dlippman
* CafeUndZopfli ported by Eugene Klyuchnikov https://github.com/eustas/CafeUndZopfli
* Brotli (c) by the Brotli Authors https://github.com/google/brotli
* Themes (c) by Brett Schwarz https://github.com/bschwarz/puml-themes
* Twemoji (c) by Twitter at https://twemoji.twitter.com/
*
*/
package ext.plantuml.com.ctreber.acearth.projection;
import ext.plantuml.com.ctreber.acearth.util.Coordinate;
import ext.plantuml.com.ctreber.acearth.util.Point2D;
import ext.plantuml.com.ctreber.acearth.util.Point3D;
import ext.plantuml.com.ctreber.acearth.util.Toolkit;
/**
* A projection for a globe on a flat surface (must be subclassed).
*
*
© 2002 Christian Treber, [email protected]
* @author Christian Treber, [email protected]
*
*/
abstract public class Projection
{
// ::remove folder when __HAXE__
// Target information
int fImageHeight;
int fImageWidth;
private double fXOffset;
private double fYOffset;
//Viewing information
private int fShiftX;
private int fShiftY;
double fScale;
private Coordinate fViewPos;
/**
In rads */
private double fViewRotation;
double fViewMagnification;
//Transformation matrix parameters */
private double fCosLat;
private double fSinLat;
private double fCosLon;
private double fSinLon;
private double fCosRot;
private double fSinRot;
/**
*
Initialize transform parameters, set offset to center of image
* (plus shifts), set scale
*/
public void initTransformTable()
{
// Set transformation parameters
fCosLat = Math.cos(Toolkit.degsToRads(fViewPos.getLat()));
fSinLat = Math.sin(Toolkit.degsToRads(fViewPos.getLat()));
fCosLon = Math.cos(Toolkit.degsToRads(fViewPos.getLong()));
fSinLon = Math.sin(Toolkit.degsToRads(fViewPos.getLong()));
fCosRot = Math.cos(Toolkit.degsToRads(fViewRotation));
fSinRot = Math.sin(Toolkit.degsToRads(fViewRotation));
fXOffset = (double)fImageWidth / 2 + fShiftX;
fYOffset = (double)fImageHeight / 2 + fShiftY;
setScale();
}
abstract protected void setScale();
/**
*
Project 3D point on y axis.
*/
abstract public double projectY(double pY);
abstract public double inverseProjectY(double pY);
/**
*
Project 3D point on x axis.
*/
abstract protected double projectX(double pX, double pZ);
abstract public double inverseProjectX(double pX);
public abstract boolean isVisible(Point3D pPoint);
public boolean isWithinImage(Point2D pPoint)
{
return (pPoint.getX() >= 0) && (pPoint.getX() < fImageWidth) &&
(pPoint.getY() >= 0) && (pPoint.getY() < fImageHeight);
}
/**
*
Translate screen point into coordinate on Earth.
*
* @param pX
* @param pY
* @return
*/
abstract public Coordinate getLocation(int pX, int pY);
/**
*
Imagine view the globe, N is up, S is down, and N0E0 is in the center.
* x is right/left, y is up/down, and z is front/rear.
*
*
Map points are located on the surface of a unit sphere (diameter = 1).
* Latitude is the angle between x and y or z and y. Longitude is the angle
* between x and z.
*
*
Why? The way we choose our global coordinate system, longitude circles
* (latidude variable) always have the same size while the size of
* latidude circles (longitude variable) depends on the latitude.
*
* @param pPoint
* @return
*/
public Point2D project2D(Point3D pPoint)
{
return new Point2D(projectX(pPoint.getX(), pPoint.getZ()),
projectY(pPoint.getY()));
}
public Point2D finalize(Point2D pPoint)
{
return new Point2D(finalizeX(pPoint.getX()), finalizeY(pPoint.getY()));
}
/**
*
Since the final mapping is relative to the center of the image
* -PI and PI get mapped to the left and right border respectively.
* But see ProjectionOrtho.setScale().
*/
public double finalizeX(double pX)
{
return fXOffset + fScale * pX;
}
/**
*
Since the final mapping is relative to the center of the image
* -PI and PI get mapped to the bottom and top border respectively.
* But see ProjectionOrtho.setScale().
*/
public double finalizeY(double pY)
{
return fYOffset - fScale * pY;
}
/**
*
Transform screen to image coordinates.
*/
public double inverseFinalizeX(double x)
{
return (x - fXOffset) / fScale;
}
/**
*
Transform screen to image coordinates.
*/
public double inverseFinalizeY(double y)
{
return (fYOffset - y) / fScale;
}
/**
*
Rotate the point according to the current rotation of Earth.
*/
public Point3D rotate(Point3D pPoint)
{
double lX = pPoint.getX();
double lY = pPoint.getY();
double lZ = pPoint.getZ();
// Do NOT inline vars - it does not work (just inline _t_ for a try).
double _c_ = fCosLon;
double _s_ = fSinLon;
double _t_ = _c_ * lX - _s_ * lZ;
lZ = _s_ * lX + _c_ * lZ;
lX = _t_;
_c_ = fCosLat;
_s_ = fSinLat;
_t_ = (_c_ * lY) - (_s_ * lZ);
lZ = (_s_ * lY) + (_c_ * lZ);
lY = _t_;
_c_ = fCosRot;
_s_ = fSinRot;
_t_ = (_c_ * lX) - (_s_ * lY);
lY = (_s_ * lX) + (_c_ * lY);
lX = _t_;
return new Point3D(lX, lY, lZ);
}
public Point3D rotateReverse(Point3D pPoint)
{
// Set transformation parameters
final double fCosLat = Math.cos(Toolkit.degsToRads(-fViewPos.getLat()));
final double fSinLat = Math.sin(Toolkit.degsToRads(-fViewPos.getLat()));
final double fCosLon = Math.cos(Toolkit.degsToRads(-fViewPos.getLong()));
final double fSinLon = Math.sin(Toolkit.degsToRads(-fViewPos.getLong()));
final double fCosRot = Math.cos(Toolkit.degsToRads(-fViewRotation));
final double fSinRot = Math.sin(Toolkit.degsToRads(-fViewRotation));
double lX = pPoint.getX();
double lY = pPoint.getY();
double lZ = pPoint.getZ();
// Do NOT inline vars - it does not work (just inline lTmp for a try).
double lCosFac;
double lSinFac;
double lTmp;
// Note that the order of the three rotation had to be reversed as well.
lCosFac = fCosRot;
lSinFac = fSinRot;
lTmp = (lCosFac * lX) - (lSinFac * lY);
lY = (lSinFac * lX) + (lCosFac * lY);
lX = lTmp;
lCosFac = fCosLat;
lSinFac = fSinLat;
lTmp = (lCosFac * lY) - (lSinFac * lZ);
lZ = (lSinFac * lY) + (lCosFac * lZ);
lY = lTmp;
lCosFac = fCosLon;
lSinFac = fSinLon;
lTmp = (lCosFac * lX) - (lSinFac * lZ);
lZ = (lSinFac * lX) + (lCosFac * lZ);
lX = lTmp;
return new Point3D(lX, lY, lZ);
}
public double getScale()
{
return fScale;
}
public Coordinate getViewPos()
{
return fViewPos;
}
public void setViewMagnification(double pViewMagnification)
{
fViewMagnification = pViewMagnification;
setScale();
}
public void setViewPos(Coordinate pViewPos)
{
fViewPos = pViewPos;
}
public void setShiftX(int pX)
{
fShiftX = pX;
}
public void setShiftY(int pY)
{
fShiftY = pY;
}
public void setViewRotation(double pViewRotation)
{
fViewRotation = pViewRotation;
}
public void setImageWidth(int pImageWidth)
{
fImageWidth = pImageWidth;
}
public void setImageHeight(int pImageHeight)
{
fImageHeight = pImageHeight;
}
}