Hi Martin,

Yes, I think so, basically you are suggesting the same thing I use. The code 
for which is below:

/**
     * @param a_Point2D
     * @param b_Point2D
     * @param distance
     * @return Point2D which lies in a straight line in the direction from
     * a_Point2D to b_Point2D and which is distance units from a_Point2D
     */
    public static Point2D getPoint2D(
            Point2D a_Point2D,
            Point2D b_Point2D,
            double distance) {
        Point2D result = null;
        double angle = a_Point2D.getAngle(b_Point2D);
        double xdiff = Math.sin(angle) * distance;
        double ydiff = Math.cos(angle) * distance;
        BigDecimal x = a_Point2D._x.add(new BigDecimal(xdiff));
        BigDecimal y = a_Point2D._y.add(new BigDecimal(ydiff));
        result = new Point2D(
                x,
                y,
                a_Point2D._DecimalPlacePrecision);
        return result;
    }

/**
     * Imprecise
     * @param a_Point2D
     * @return Angle to the y axis clockwise. Default 0.0d.
     */
    public double getAngle(Point2D a_Point2D) {
        double dx = a_Point2D._x.doubleValue() - _x.doubleValue();
        double dy = a_Point2D._y.doubleValue() - _y.doubleValue();
        if (dy == 0.0d) {
            if (dx == 0.0d) {
                return 0.0d;
            } else {
                if (dx > 0.0d){
                    return Math.PI / 2.0d;
                } else {
                    return (3.0d * Math.PI) / 2.0d;
                }
            }
        } else {
            if (dy > 0.0d){
                if (dx == 0.0d) {
                    return 0.0d;
                } else {
                    if (dx > 0.0d){
                        return Math.atan(dx / dy);
                    } else {
                        return (2.0d * Math.PI) - Math.atan(Math.abs(dx) / dy);
                    }
                }
            } else {
                // dy < 0.0d
                if (dx == 0.0d) {
                    return Math.PI;
                } else {
                    if (dx > 0.0d){
                        return Math.PI - Math.atan(dx / Math.abs(dy));
                    } else {
                        return Math.PI + Math.atan(Math.abs(dx) / Math.abs(dy));
                    }
                }
            }
        }
    }

Best wishes,

Andy
http://www.geog.leeds.ac.uk/people/a.turner/

From: Martin [mailto:[email protected]]
Sent: 08 April 2010 11:38
To: [email protected]; 
[email protected]
Subject: [Geotools-gt2-users] How to calculate a Point given another point, a 
distance and a angle?

Hi all,


I know this is not a typical question for a user list but I least I can try to 
find help here;-)

I have given a vehicle (it's a point) and the movementpath of the vehicle (it's 
a "directed" linestring) ! I computed the degree of the movement!
For example moving from
(0,0) to (0.5) the movement direction is/has 0 degree
(0,0) to (5.0) the movement direction is/has 90 degree
(0,0) to (0.-5) the movement direction is/has 180 degree
(0,0) to (-5.0) the movement direction is/has 270 degree

but for visualization each vehicle occupies a rectangle and I want to compute 
the position of the rectangle "!beneath!" the street!
So  I have given a point(vehicles point on the streetnetwork) the 
movementdegree and the distance(width of the rectangle/2)!
And I need to compute the point!

(situation is shown in attachment)

My idea is for computing the point (x,y) is:
x =  sin(degree)* distance + x(value of point on street)
y = cos(degree)*distance+y(value of point on street)

What do you say? Is the formular correct?

Cheers,
Martin

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to