前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >直线的正交/平行的判定

直线的正交/平行的判定

作者头像
灯珑LoGin
发布2022-10-31 13:12:30
4480
发布2022-10-31 13:12:30
举报
文章被收录于专栏:龙进的专栏

直线点乘为0则正交,直线叉乘为0则平行。

题目:CGL_2_A

代码:

代码语言:javascript
复制
#include <iostream>
using namespace std;

class Point
{
public:
    double x, y;
    Point()
    {
    }
    Point(double x, double y)
    {
        (*this).x = x;
        (*this).y = y;
    }

    double operator^(const Point &p) const //叉乘
    {
        return x * p.y - y * p.x;
    }

    double operator*(const Point &p) const //点乘
    {
        return x * p.x + y * p.y;
    }
    Point operator-(const Point &p) const
    {
        return Point(x - p.x, y - p.y);
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int q;
    cin >> q;
    Point p[4];
    double x, y;
    while (q--)
    {
        for (int i = 0; i < 4; ++i)
        {
            cin >> x >> y;
            p[i] = Point(x, y);
        }

        if (!((p[1] - p[0]) * (p[3] - p[2])))
            cout << 1 << endl;
        else if (!((p[1] - p[0]) ^ (p[3] - p[2])))
            cout << 2 << endl;
        else
            cout << 0 << endl;
    }
}

转载请注明来源:https://www.longjin666.top/?p=775

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021年2月1日20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档