• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ line类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中line的典型用法代码示例。如果您正苦于以下问题:C++ line类的具体用法?C++ line怎么用?C++ line使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了line类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: line_line

const collision line_line(const line &a, const line &b)
{
	collision r;

	auto m1 = (a.position.y - a.end.y) / (a.position.x - a.end.x);
	auto m2 = (b.position.y - b.end.y) / (b.position.x - b.end.x);

	auto b1 = a.position.y - m1*a.position.x;
	auto b2 = b.position.y - m2*b.position.x;

	float x = (b2 - b1) / (m1 - m2);
	float y = m1*x + b1;

	if ((a.position.x - a.end.x) == 0) // if a is a vertical line, then there is only 1 possible x value.
	{	x = a.position.x;	y = m2 *x + b2;	}
	if ((b.position.x - b.end.x) == 0)
	{	x = b.position.x;	y = m1 *x + b1;	}

	r.contact = { x, y }; point p(r.contact);
	r.result = circle_point(circle(a.mid(), a.length() / 2), p).result
		    && circle_point(circle(b.mid(), b.length() / 2), p).result;

	if (m1 == m2)
	{
		r.result = false;
		return r;
	}
	return r;
}
开发者ID:Zac-King,项目名称:GameAI,代码行数:29,代码来源:shapes.cpp


示例2: intersec

int intersec(const line& l1, const line& l2,
             point& res){
  assert(!(l1.v == point()));
  assert(!(l2.v == point()));
  if (vp(l1.v,l2.v) == point()){
    if (vp(l1.v, l1.p - l2.p) == point())
      return 2; // same
    return 0; // parallel
  }
  point n = vp(l1.v,l2.v);
  point p = l2.p - l1.p;
  if (sgn(sp(n,p)))
    return 0; // skew
  ld t;
  if (sgn(n.x))
    t = (p.y * l2.v.z - p.z * l2.v.y) / n.x;
  else if (sgn(n.y))
    t = (p.z * l2.v.x - p.x * l2.v.z) / n.y;
  else if (sgn(n.z))
    t = (p.x * l2.v.y - p.y * l2.v.x) / n.z;
  else
    assert(false);
  res = l1.p + l1.v * t;
  assert(l1.on(res)); assert(l2.on(res));
  return 1; // intersects
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:26,代码来源:geom-3d.cpp


示例3: make_tuple

std::tuple<bool, float> line::intersect(const line &other) const {

    //from http://stackoverflow.com/a/1968345
    double p0_x = m_origin.x();
    double p0_y = m_origin.y();
    double p1_x = m_target.x();
    double p1_y = m_target.y();
    double p2_x = other.origin().x();
    double p2_y = other.origin().y();
    double p3_x = other.target().x();
    double p3_y = other.target().y();

    double s1_x = p1_x - p0_x;
    double s1_y = p1_y - p0_y;
    double s2_x = p3_x - p2_x;
    double s2_y = p3_y - p2_y;

    if ((-s2_x * s1_y + s1_x * s2_y) == 0) {
        return std::make_tuple(false, 0.0f);
    }

    double s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
    double t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);

    double w = 0.1;
    if (s >= 0-w && s <= 1+w && t >= 0-w && t <= 1+w)
    {
        // Collision detected
        return std::make_tuple(true, t);
    }
    return std::make_tuple(false, 0.0f);
}
开发者ID:mohlek,项目名称:game-of-life,代码行数:32,代码来源:line.cpp


示例4: isInPlane

	bool plane::isInPlane(const line& l)const
	{
		auto dot = norm_.dotProduct(l.dir());
		if (!floatEqual(dot, 0.0f))
			return false;

		return isInPlane(l.start());
	}
开发者ID:zouxiaohang,项目名称:zengine,代码行数:8,代码来源:plane.cpp


示例5: intersect

point intersect(line & l, segment s) {
    double da = fabs(l.dist(s.a)), db = fabs(l.dist(s.b));
    if (da + db < eps) {
        return s.a;
    } else {
        double t = da / (da + db);
        return s.a + (s.b - s.a) * t;
    }
}
开发者ID:AVBelyy,项目名称:CompGeometry,代码行数:9,代码来源:hp-intersection-nlogm.cpp


示例6: draw_line

      void draw_line ( line l )
	{
	  XDrawLine ( m_display,
		      m_window_id,
		      m_gc,
		      l.point1().x(),
		      l.point1().y(),
		      l.point2().x(),
		      l.point2().y() );
	}
开发者ID:8l,项目名称:x11,代码行数:10,代码来源:graphics_context.hpp


示例7:

	std::pair<bool, vector3> plane::intersection(const line& l)const
	{
		auto ret = std::make_pair<bool, vector3>(false, vector3());
		if (isInPlane(l))
			return ret;

		ret.first = true;
		auto t = (norm_.dotProduct(point_) - norm_.dotProduct(l.start())) / (norm_.dotProduct(l.dir()));
		ret.second = l.start() + t * l.dir();
		return ret;
	}
开发者ID:zouxiaohang,项目名称:zengine,代码行数:11,代码来源:plane.cpp


示例8: res

pt operator&(const line &l1, const line &l2) {
  double d = l1.a * l2.b - l1.b * l2.a;
  assert(fabs(d) > eps);
  pt res(
    (l1.b * l2.c - l1.c * l2.b) / d,
    (l1.a * l2.c - l1.c * l2.a) / -d
  );
  assert(l1.side(res) == 0);
  assert(l2.side(res) == 0);
  return res;
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:11,代码来源:geom-double.cpp


示例9: intersection

    // gets the intersection between two lines (not segments)
    // ot : the other line
    // if they are equal, returns nan
    // if they are parallel, returns inf
    // else, returns the x on which the intersection occurs
    double intersection (const line<cood> & ot) const {
        double a[2] = {slope(), ot.slope()};
        double b[2] = {intercept(a[0]), ot.intercept(a[1])};

        if (abs(a[0]-a[1]) < eps) {
            if (abs(b[0]-b[1]) < eps) return 0./0.;
            return 1./0.;
        } else {
            debug("%.2f/%.2f", b[0]-b[1], a[1]-a[0]);
            return (b[0]-b[1])/(a[1]-a[0]);
        }
        
        return true;
    }
开发者ID:victorsenam,项目名称:treinos,代码行数:19,代码来源:old.cpp


示例10: assert

    const double
    line::getDistFromLine(const line& l) const
    {
        assert(this->is_Set() && l.is_Set());
        double this_ori = this->getOrientation();
        double other_ori = l.getOrientation();
        double diff_ori = fabs(this_ori - other_ori);

        double d = (point2Line(*this, l.m_endp1) <= point2Line(*this, l.m_endp2)) ?
                point2Line(*this, l.m_endp1): point2Line(*this, l.m_endp2);

        return d + 1.5*diff_ori; // 1.5 is a magic number

        return 0;
    }
开发者ID:91yuan,项目名称:simple_lane_tracking,代码行数:15,代码来源:line.cpp


示例11: overlap

	bool overlap(line another){
		if(type !=another.type){
			return false;
		}
		if(type==0){
			if (y0!=another.y0){
				return false;
			}
		}
		if(type==1){
			if (x0!=another.x0){
				return false;
			}
		}
		if(type==2 ){
			if (y0-x0!=another.y0-another.x0){
				return false;
			}
		}
		if(type==3 ){
			if (y0+x0!=another.y0+another.x0){
				return false;
			}
		}
		line possible_merge_line=merge(another);
		if(possible_merge_line.len()<=len()+another.len()){
			return true;
		}
		return false;
	}
开发者ID:shijiaxin,项目名称:algorithm,代码行数:30,代码来源:old_wangyi_3.cpp


示例12: main

int main () {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        debug("%d: ", i);
        scanf("%lld %lld", &v.s.x, &v.s.y);
        scanf("%lld %lld", &v.t.x, &v.t.y);

        scanf("%lld %lld", &a[0].x, &a[0].y);
        scanf("%lld %lld", &a[2].x, &a[2].y);

        a[1].x = a[0].x;
        a[1].y = a[2].y;

        a[3].x = a[2].x;
        a[3].y = a[0].y;

        if (v.s.inside({a[0], a[1], a[2], a[3]}) || v.t.inside({a[0], a[1], a[2], a[3]})) {
            debug("1");
            printf("T\n");
            continue;
        }

        int j = 0;
        for (j = 0; j < 4; j++) {
            line<> u(a[j], a[(j+1)%4]);

            double x = v.intersection(u);
            if (x == 0./0.) {
                debug("e");
                if (v.contains(u.s.x) || v.contains(u.t.x) || u.contains(v.s.x) || u.contains(v.t.x))
                    break;
            } else if (v.contains(x) && u.contains(x)) {
                debug("c");
                break;
            } else {
                debug("[%.1f]", x);
            }
        }

        if (j == 4) 
            printf("F\n");
        else
            printf("T\n");
    }
}
开发者ID:victorsenam,项目名称:treinos,代码行数:46,代码来源:old.cpp


示例13: drawLine

void drawLine(line l) {
    if (l.isDiameter()) {
        glBegin(GL_LINE_STRIP);
        glVertex2d(l.getLeft().getX(), l.getLeft().getY());
        glVertex2d(l.getRight().getX(), l.getRight().getY());
        glEnd();
        return;
    }
    double middle = l.getCenter().arg() + M_PI;
    double deflection = atan(1/l.getRadius());
    double start = middle - deflection;
    double end = middle + deflection;
    drawArc(l.getCenter(), l.getRadius(), start, end);
}
开发者ID:shsty,项目名称:Geometry,代码行数:14,代码来源:draw.cpp


示例14: check_cross

void check_cross(const pt &cent, const double &r, const line &l, int need_cnt) {
  vector<pt> res = cross(cent, r, l);
  printf("check circle&line\n");
  for (int i = 0; i < sz(res); i++) {
    printf("  %.2lf %.2lf\n", res[i].x, res[i].y);
    assert(l.side(res[i]) == 0);
    assert(fabs((cent - res[i]).dist2() - r * r) < eps);
  }
  assert(sz(res) == need_cnt);
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:10,代码来源:geom-double.cpp


示例15: cross

vector<pt> cross(const pt &center, double r,
                 const line &l) {
  double di = l.distz(center);
  double d2 = l.norm2();
  assert(fabs(d2) > eps);
  pt mid = center + pt(l.a, l.b) * (-di / d2);
  #ifdef DEBUG
  assert(l.side(mid) == 0);
  #endif

  double s = r * r - di * di / d2;
  if (s < -eps) return vector<pt>();
  if (fabs(di * di - r * r * d2) < eps)
    return vector<pt>(1, mid);

  pt off = pt(-l.b, l.a) * sqrt(s / d2);
  assert(fabs(off.dist2() - s) < eps);
  vector<pt> res;
  res.pb(mid + off);
  res.pb(mid - off);
  return res;
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:22,代码来源:geom-double.cpp


示例16: closest

void closest(const line& l1,const line& l2,
             point& p1,point& p2){
  if (vp(l1.v,l2.v) == point()){
    p1 = l1.p;
    p2 = l2.p - l1.v * /*BOXNEXT*/
         (sp(l1.v,l2.p - l1.p) / l1.v.dist2());
    return;
  }
  point p = l2.p   - l1.p;
  ld t1 = (
           sp(l1.v,p) * l2.v.dist2() -
           sp(l1.v,l2.v) * sp(l2.v,p)
          ) / vp(l1.v,l2.v).dist2();
  ld t2 = (
             sp(l2.v,l1.v) * sp(l1.v,p) -
             sp(l2.v,p) * l1.v.dist2()
          ) / vp(l2.v,l1.v).dist2();
  p1 = l1.p + l1.v * t1;
  p2 = l2.p + l2.v * t2;
  assert(l1.on(p1));
  assert(l2.on(p2));
}
开发者ID:kunyavskiy,项目名称:SPbSU4-Team-Notebook,代码行数:22,代码来源:geom-3d.cpp


示例17: shortestDistance

pReal line::shortestDistance( line a )
    {
    pVector cP = direction.cross( a.direction );
    if( direction.normalise() == a.direction.normalise() )
        {
        return ( a.sample( plane( position, direction ).collision( a ) ) - position ).length();
        }
    if( cP != cP )
        {
        return 0;
        }
    return fabs( cP.dot( a.position - position ) / cP.length( ) );
    }
开发者ID:davidmueller13,项目名称:vexx,代码行数:13,代码来源:shape.line.cpp


示例18: linePolyCollision

bool linePolyCollision( line & testLine, polygon & testPoly)
{
	// 2 intersections should be a collision
	polyIterator itr = testPoly.begin();
	int collCounter = 0;
	int pointCount = 1;
	while( itr != testPoly.end() )
	{
		point collPoint = testLine.checkIntersection( *itr );
		if ( testLine.isPointOnLine( collPoint ) )
		{
			collCounter++;
		}
		++itr;
		pointCount++;
	}

	if( collCounter > 1 )
	{
		return true;
	}
	return false;
}
开发者ID:thurtt,项目名称:gameengine,代码行数:23,代码来源:collision.cpp


示例19:

bool line<2>::intersection_point(const line<2>& ln, point<2>& p) const {
	// returns true if an intersection with line exists, 
	// and p as the intersection point
	if ((*this) == ln) {
		p.x() = p.y() = 0.0;
		return true;
	}
	if (parallelQ(ln))
		return false;

	p.x() = (ln.b * d - b * ln.d) / (ln.a * b - a * ln.b);
	if (fabs(b) > EPSILON)	// test for vertical line
		p.y() = - (a * p.x() + d) / b;
	else
		p.y() = - (ln.a * p.x() + ln.d) / ln.b;

	return true;
}
开发者ID:frandibar,项目名称:acm-valladolid,代码行数:18,代码来源:acm.cpp


示例20: main

int main () {
    scanf("%d", &n);

    while (n--) {
        scanf("%d %d %d %d", &l.s.x, &l.s.y, &l.t.x, &l.t.y);
        scanf("%d %d", &v[0].x, &v[0].y);
        scanf("%d %d", &v[2].x, &v[2].y);

        v[1].x = v[0].x; v[1].y = v[2].y;
        v[3].x = v[2].x; v[3].y = v[0].y;

        bool ok = 0;
        if (l.s.inside({v[0], v[1], v[2], v[3]}) || l.t.inside({v[0], v[1], v[2], v[3]}))
            ok = 1;
        else {
            for (int j = 0; j < 4; j++)
                ok |= l.intersects(line<ll>(v[j], v[(j+1)%4]));
        }
        
        if (ok) printf("T\n");
        else printf("F\n");
    }
}
开发者ID:victorsenam,项目名称:treinos,代码行数:23,代码来源:191.cpp



注:本文中的line类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ list_t类代码示例发布时间:2022-05-31
下一篇:
C++ lduMatrix类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap