How to calculate coordinates of third point in a t

2019-03-03 22:04发布

问题:

I have a triangle and I know the coordinates of two vertices: A=(x1,y1),B=(x2,y2) All the angles: ABC=90∘,CAB=30∘ and BCA=60∘ and all the edge lengths. How can I find the coordinates of the third vertex C=(x3,y3)?

I know there are two solutions (I want both).

回答1:

  1. You know p1 and p2. You know the internal angles.
  2. Make a ray from p1 trough p2, and rotate it CW or CCW 30° around p1.
  3. Make a line trough p1 and p2, and rotate it 90° around p2.
  4. Calculate the intersections.

You get the points:

x3 = x2 + s*(y1 - y2)
y3 = y2 + s*(x2 - x1)

and

x3 = x2 + s*(y2 - y1)
y3 = y2 + s*(x1 - x2)

where s = 1/sqrt(3) ≈ 0.577350269



回答2:

In a 30-60-90 right triangle, smallest leg (the smallest side adjacent the 90 degree angle) has length of 1/2 of the hypotenuse (the side opposite to 90 degree angle), so since you have the side lengths, you can determine which leg is the line segment AB.

From that you deduce where do the angles go.

Then to compute the coordinate you just need to pick the point on the circle of the radius with the correct radius length at the correct angle.

Two solutions come from measuring the angle clock-wise or counter-clockwise, and result in symmetrical triangles, with the edge AB being the line of symmetry.

Since you already have given the angles, compute the length of AB via quadratic formula

L(AB) = Sqrt[(x1-x2)^2 + (y1-y2)^2].

Now, let x = L(AC) = 2*L(BC) so since it is the right triangle,

L(AC)^2 = L(BC)^2 + L(AB)^2,

x^2 = (0.5x)^2 + L(AB)^2, so L(AB) = x*Sqrt[3]/2, and since you already computed L(AB) you now have x.

The angle of the original AB is a = arctan([y2-y1]/[x2-x1]). Now you can measure 30 degrees up or down (use a+30 or a-30 as desired) and mark the point C on the circle (centered at A) of radius x (which we computed above) at the angle a +/- 30.

Then, C has coordinates

x3 = x1 + x*cos(a+30)

y3 = y1 + x*sin(a+30)

or you can use (a-30) to get the symmetrical triangle.



回答3:

Here is the code to return points of full polygon if two points and number of sides are provided as input. This is written for Android(Java) and the logic can be re-used for other languages

private static final float angleBetweenPoints(PointF a, PointF b) {
    float deltaY = b.y - a.y;
    float deltaX = b.x - a.x;
    return (float) (Math.atan2(deltaY, deltaX));

}
private static PointF pullPointReferenceToLineWithAngle(PointF a, PointF b,
        float angle) {

    float angleBetween = angleBetweenPoints(b, a);
    float distance = (float) Math.hypot(b.x - a.x, b.y - a.y);
    float x = (float) (b.x + (distance * Math.cos((angleBetween + angle))));
    float y = (float) (b.y + (distance * Math.sin((angleBetween + angle))));
    return new PointF(x, y);
}

private static List<PointF> pullPolygonPointsFromBasePoints(PointF a,
        PointF b, int noOfSides) {
    List<PointF> points = new ArrayList<>();
    points.add(a);
    points.add(b);
    if (noOfSides < 3) {
        return points;
    }
    float angleBetweenTwoSides = (float) ((((noOfSides - 2) * 180) / noOfSides)
            * Math.PI / 180);
    for (int i = 3; i <= noOfSides; i++) {
        PointF nextPoint = pullPointReferenceToLineWithAngle(
                points.get(i - 3), points.get(i - 2), angleBetweenTwoSides);
        points.add(nextPoint);
    }
    return points;
}

Usage is onDraw method:

PointF a = new PointF(100, 600);
    PointF b = new PointF(300, 500);
    int noOfSides = 3;

    List<PointF> polygonPoints = pullPolygonPointsFromBasePoints(a, b,
            noOfSides);

    drawPolyPoints(canvas, noOfSides, polygonPoints);


回答4:

This is a right angled triangle. The angle ABC is 90 degrees, so calculate the vector joining A to B and call this AA and normalise it:

 AA = (x2-x1,y2-y1) / |(x2-x1,y2-y1)|

A unit vector perpendicular to AA is given by

 BB = (-(y2-y1),x2-x1) / |(x2-x1,y2-y1)|

Because AC is perpendicular to AB all you can obtain your first point P1 as

 P1 = (x2,y2) + K * BB

where K is the scalar value equal to the length of side AC (which you say you already know in the question). Your second solution point P2 is then simply given by going in the negative BB direction

 P2 = (x2,y2) - K * BB