Package chunmap.model.elem

Source Code of chunmap.model.elem.Triangle

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.model.elem;

import chunmap.model.coord.CPoint;
import chunmap.model.coord.Coordinate2D;

/**
* @author chunquedong
*
*/
public class Triangle {

  private final CPoint p1;
  private final CPoint p2;
  private final CPoint p3;

  /**
   * @param p1
   * @param p2
   * @param p3
   */
  public Triangle(CPoint p1, CPoint p2, CPoint p3) {
    super();
    this.p1 = p1;
    this.p2 = p2;
    this.p3 = p3;
  }

  public CPoint getP1() {
    return p1;
  }

  public CPoint getP2() {
    return p2;
  }

  public CPoint getP3() {
    return p3;
  }

  /**
   * 三角形代数面积
   *
   * @return
   */
  public double computeArea() {
    Vector v1 = new Vector(p1, p2);
    Vector v2 = new Vector(p1, p3);
    double a = v1.get2DCrossProduct(v2);
    return a / 2d;
  }

  /**
   * 外接圆圆心,垂直平分线法
   */
  public CPoint computeOuterCenter() {
    Line l1 = getLine(p1, p2);
    Line l2 = getLine(p2, p3);

    CPoint point = l1.crossPoint(l2);
    return point;
  }

  public CPoint computeCenter() {
    double x = (p1.getX() + p2.getX() + p3.getX()) / 3d;
    double y = (p1.getY() + p2.getY() + p3.getY()) / 3d;

    return new Coordinate2D(x, y);
  }

  private Line getLine(CPoint p1, CPoint p2) {
    LineSegment s1 = new LineSegment(p1, p2);
    Line l1 = s1.toLine();
    double k1 = l1.getVerticalK();
    CPoint p = s1.getMiddlePoint();
    Line vl1 = new Line(p, k1);

    return vl1;
  }
}
TOP

Related Classes of chunmap.model.elem.Triangle

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.