Java-使绘图点接近线性-完全线性 [英] Java - Make Plot Points, Near Linear - Exactly Linear

查看:110
本文介绍了Java-使绘图点接近线性-完全线性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何改变接近"线性(在阈值内),实际上是线性的点?

How would I go about changing points that are 'near' linear (within a threshold), actually linear?

我有一些代码可以检查3个点是否彼此线性(给定或取走),我想用100%内联的新坐标替换那些坐标.

I have some code that checks if 3 points are linear to one another (give or take), and I want to replace those coordinates with new ones that are 100% inline.

        double distance = (x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3);

        double threshold = 4;

        if (Math.abs(distance) <= threshold) {
            // is Near line
            return true;
        }
        else
            return false;

这是我的另一篇文章的延伸...这不是转发,只是一个相关主题:

This is an EXTENSION of another post of mine... This is NOT a repost, simply a related topic:

Java-平均线性图图

推荐答案

将点捕捉到直线的技术术语是将点投影到直线(-段)

The technical term for snapping a point to a line is projecting a point to a line(-segment)

唯一的问题是:点应该投影到线还是线段上? (线段仅在两个点之间,该线具有无限长,并且穿过两个点)

The only question that remains: Should the points projected to the line or to the line segment? (A line segment is only between two points, the line has infinity length and goes through both points)

以下代码可同时解决这两个问题: 为了也允许将点投影到点A-> B之外的线的另一端,代码会更加简单,但这也包含在下面的链接中.

The code below solves both: To allow also projecting points to th epart of the line that is outside of points A->B, the code would be much simpler, but this is covered in the link below, too.

请参见 http://forums.codeguru .com/showthread.php?194400-Distance-between-point-and-line-segment

投影点位于变量(xx,yy)中: (xx,yy)是lineSegment上最接近(cx,cy)的点

The projected point is in the variables (xx,yy): (xx,yy) is the point on the lineSegment closest to (cx,cy)

这篇关于Java-使绘图点接近线性-完全线性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆