- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在用 Java(尤其是 Android)制作显示如下内容的东西:
用户可以拖动框的角,正如预期的那样,虚线应相应移动,始终有 3 条水平线(一条在中间,一条在顶部和底部之间,一条在 25% 处,一条在 75% 处)和3条垂直线。然而,如果左边缘或右边缘是无穷大(当用户第一次看到屏幕时),它看起来像这样:
如何更改我的代码,以便考虑到无限斜率边缘并仍然显示所需的屏幕?这是我的代码,用于检测虚线的位置、它们的斜率,最后将它们绘制到屏幕上。
//get edge slopes to calculate dashed lines
//c1X is the top left corner X position, c2X is for the top right corner, etc.
float topLineSlope = (c2Y - c1Y)/(c2X - c1X);
float rightLineSlope = (c3Y - c2Y)/(c3X - c2X);
float bottomLineSlope = (c4Y - c3Y)/(c4X - c3X);
float leftLineSlope = (c1Y - c4Y)/(c1X - c4X);
//b in y=mx+b
float topLineB = c1Y - (topLineSlope * c1X);
float rightLineB = c2Y - (rightLineSlope * c2X);
float bottomLineB = c3Y - (bottomLineSlope * c3X);
float leftLineB = c4Y - (leftLineSlope * c4X);
//final dashed line coordinates
float topLineMiddleX = (c1X + c2X) / 2.0f;
float topLineMiddleY = topLineSlope * topLineMiddleX + topLineB;
float bottomLineMiddleX = (c3X + c4X) / 2.0f;
float bottomLineMiddleY = bottomLineSlope * bottomLineMiddleX + bottomLineB;
float leftLineMiddleX = (c4X + c1X) / 2.0f;
float leftLineMiddleY = leftLineSlope * leftLineMiddleX + leftLineB;
float rightLineMiddleX = (c2X + c3X) / 2.0f;
float rightLineMiddleY = rightLineSlope * rightLineMiddleX + rightLineB;
float topLineLeftX = (c1X + topLineMiddleX) / 2.0f;
float topLineLeftY = topLineSlope * topLineLeftX + topLineB;
float bottomLineLeftX = (c4X + bottomLineMiddleX) / 2.0f;
float bottomLineLeftY = bottomLineSlope * bottomLineLeftX + bottomLineB;
float topLineRightX = (topLineMiddleX + c2X) / 2.0f;
float topLineRightY = topLineSlope * topLineRightX + topLineB;
float bottomLineRightX = (c3X + bottomLineMiddleX) / 2.0f;
float bottomLineRightY = bottomLineSlope * bottomLineRightX + bottomLineB;
float leftLineTopX = (c1X + leftLineMiddleX) / 2.0f;
float leftLineTopY = leftLineSlope * leftLineTopX + leftLineB;
float rightLineTopX = (c2X + rightLineMiddleX) / 2.0f;
float rightLineTopY = rightLineSlope * rightLineTopX + rightLineB;
float leftLineBottomX = (leftLineMiddleX + c4X) / 2.0f;
float leftLineBottomY = leftLineSlope * leftLineBottomX + leftLineB;
float rightLineBottomX = (c3X + rightLineMiddleX) / 2.0f;
float rightLineBottomY = rightLineSlope * rightLineBottomX + rightLineB;
canvas.drawLine(topLineMiddleX, topLineMiddleY, bottomLineMiddleX, bottomLineMiddleY, dashedLine);
canvas.drawLine(leftLineMiddleX, leftLineMiddleY, rightLineMiddleX, rightLineMiddleY, dashedLine);
canvas.drawLine(topLineLeftX, topLineLeftY, bottomLineLeftX, bottomLineLeftY, dashedLine);
canvas.drawLine(topLineRightX, topLineRightY, bottomLineRightX, bottomLineRightY, dashedLine);
canvas.drawLine(leftLineTopX, leftLineTopY, rightLineTopX, rightLineTopY, dashedLine);
canvas.drawLine(leftLineBottomX, leftLineBottomY, rightLineBottomX, rightLineBottomY, dashedLine);
最佳答案
如果您不使用直线或斜率方程,这将非常容易。您所做的是通过查找 x 坐标对的平均值来计算所有 x 坐标。然后,您将这些 x 坐标代入了边的方程式。正如您所确定的,如果斜率是无限的,这将不起作用。有一个非常简单的解决方案。您所要做的就是按照与计算 x 坐标完全相同的方式计算 y 坐标,问题就会消失。
关于java - 计算直线的斜率(如果它是无穷大),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27812142/
这一章实现的连接线,目前仅支持直线连接,为了能够不影响原有的其它功能,尝试了2、3个实现思路,最终实测这个实现方式目前来说最为合适了。 请大家动动小手,给我一个免费的 Star 吧~ 大家
本章分享一下如何使用 Konva 绘制基础图形:矩形、直线、折线,希望大家继续关注和支持哈! 请大家动动小手,给我一个免费的 Star 吧~ 大家如果发现了 Bug,欢迎来提 Issue
本章响应小伙伴的反馈,除了算法自动画连接线(仍需优化完善),实现了可以手动绘制直线、折线连接线功能。 请大家动动小手,给我一个免费的 Star 吧~ 大家如果发现了 Bug,欢迎来提 Is
我有一条线(两点(x,y)(x1,y1))和一个带有焦点(rx,ry)的矩形。我需要帮助找出线和矩形之间的碰撞点,C++ 中的一个例子会有所帮助。 最佳答案 我不知道如何仅用“焦点”来表示矩形。您将需
让我们画一条线和一个圆: canvas.create_line(x0,y0,x1,y1) canvas.create_oval(x0,y0,x1,y1) 如何计算每个像素的像素数? 最佳答案 你不能。
本文实例讲述了php使用gd2绘制基本图形。分享给大家供大家参考,具体如下: 应用GD2函数可以绘制的图形有多种,最基本的图形包括条、圆、方形等。无论开发人员绘制多么复杂的图形,都是在这些最基本的
我已经尝试了所有改变颜色的方法: call s:h("Underlined", {"fg": s:norm, "gui": "underline", "cterm": "underline"})
为什么以下行有时会在 chrome 开发控制台中产生消息“未定义不是函数”: (callbackOrUndefined || function() {})(); 这个想法是,如果回调为真,即函数,则执
我想在 MS Chart 中实现直线(分段拟合)图表。 我知道 X 轴上的点 [最小值 = 1.4,最大值 = 2.2]。我已将所有这些点都放在折线图上。 现在的要求是我如何知道 X 轴上的点 [最小
所以我正在使用 charts.js http://www.chartjs.org/我试图使 2 个点之间的线是直线而不是弯曲的,没有明显的原因。 现在看起来是这样的 http://imgur.com/
我已将我的机器人发布到 Azure。现在我要开发自己的聊天用户界面。我想在 JavaScript 中使用 Direct Line API 来调用机器人。 如何在 JavaScript 中使用 Dire
这个有点难解释。我有一个整数列表。因此,例如,[1, 2, 4, 5, 8, 7, 6, 4, 1] - 当根据元素编号绘制时,它类似于凸图。我如何以某种方式从列表中提取此“形状”特征?它不必特别准确
我在学习 javaScript 和 jQuery 的第一周,我正在尝试制作一些动画。 基本上我想要做的就是让这些箭头从屏幕开始,从一侧进入,通过 throw 目标,然后离开屏幕的另一侧。 理想情况下,
假设我有一个向导并且有 3 个部分,假设它是这样的。 [A]----[B]----[C] 假设当前在范围内选择了 A。这是一个彩色的红色圆圈。当 B 在范围内被选中时,就可以移动一个对象(假设一条彩色
我正在使用 botframework-directlinejs NodeJS SDK 为我的机器人前端实现一个新 channel 。该 channel 将提供一些自定义反向 channel 功能;但是
我正在使用直线执行 hql 查询。该作业似乎没有出现在 HDP 2.6 上 Spark History 服务器的资源管理器中。如何让它运行在 Yarn 上? 谢谢 最佳答案 Beeline 是一个 A
我目前正在尝试找到一种如何使用 Google Maps Api V3 获得直线路线的方法。 我已经设法使用地理编码和方向服务来获取从 A 点到 B 点的路线,包括两条替代路线。我还尝试过“无高速公路”
我有一个简单的 Canvas html5。它可以通过选择选项绘制一些形状,如直线、圆形、矩形、多边形,但现在我想让所有绘制都可拖动(如果可能的话)可调整大小,没有 3 部分库,只有纯 JS。
我正在使用在 Kerberos 中添加的帐户启动 beeline 来测试 Sentry: beeline -u "jdbc:hive2://IP:10000/;principal=test_table
我正在使用普通的 html/javascript Canvas (无库)。我有一种从两点计算 Angular 方法,我的理论是,我获取 Angular 并通过循环所需的水平距离 (x) 并对该 Ang
我是一名优秀的程序员,十分优秀!