zoukankan      html  css  js  c++  java
  • 7.5---两个正方形分成对半的直线(CC150)

    最主要的思路:1,这条直线就是要把两个正方形的中点链接。

    2,注意的特殊情况:中心点重合。

    答案:

    public class Solution {
        
        public static void main(String[] args){
            Point[] a = {new Point(136,6278),new Point(3958,6278),new Point(3958,2456),new Point(136,2456)};
            Point[] b = {new Point(-3898,11132),new Point(7238,11132),new Point(7238,-4),new Point(-3898,-4)};
            System.out.println(Arrays.toString(getBipartition(a,b)));
        }
        public static  double[] getBipartition(Point[] a, Point[] b) {
            // write code here
            double[] res = new double[2];
            Center c1 = new Center((a[0].x + a[1].x)/2.0,(a[0].y + a[3].y)/2.0);
            Center c2 = new Center((b[0].x + b[1].x)/2.0,(b[0].y + b[3].y)/2.0);
            
            System.out.println(c2.x);
            if(c1.x == c2.x && c1.y == c2.y){
                res[0] = (a[2].y-a[0].y)*1.0 / (a[2].x - a[0].x);
                res[1] = a[0].y - res[0] * a[1].x;
            }
            else{
                
                res[0] = (c2.y - c1.y) / (c2.x - c1.x);
                res[1] = c2.y - res[0] * c2.x;
            }
            
            return res;
        
        }
    }
    
    class Center{
        double x;
        double y;
        Center(double x, double y){
            this.x = x;
            this.y = y;
        }
    }
    class Point {
        int x;
        int y;
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public Point() {
            this.x = 0;
            this.y = 0;
        }
    }
  • 相关阅读:
    ASP脚本获取服务器全部参数列表说明
    HTML基础教程
    HTML5代码大全
    CSS 属性大全
    Web前端单词大全
    css常用代码大全
    曾国藩:诚敬静谨恒!
    鼠标经过显示菜单
    月入3000+项目
    右侧菜单显示隐藏
  • 原文地址:https://www.cnblogs.com/yueyebigdata/p/5088731.html
Copyright © 2011-2022 走看看