- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我用html做了两个三 Angular 形div。我正在使用 jquery Ui 使它们可拖动。
现在我想重叠这两个三 Angular 形并用另一种颜色为重叠部分着色,如下所示:
你知道我如何用 jQuery 做到这一点吗?
$(document).ready(function() {
$(".triangle").draggable();
})
#triangle_1 {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid #00ff00;
}
#triangle_2 {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class = "triangle"
id = "triangle_1" > </div>
<div class="triangle" id="triangle_2"></div >
这是我使用矩形而不是三 Angular 形的工作解决方案 (link)。
最佳答案
jQuery API 没有找到 2 个三 Angular 形样式 DIV 的交集的方法。
您可以使用数学找到“红色相交三 Angular 形”:
第 I 部分:找到红色多边形的顶点
如果您在上面的#3 中恰好找到了 3 个交点,那么这 2 个原始三 Angular 形相交形成了一个新的三 Angular 形——然后继续第二部分...
第二部分:根据第一部分中找到的 3 个交点创建三 Angular 形多边形
找到新三 Angular 形的“中心点”。这是它的 x 和 y 的算术平均值:centerX = (vertex1.x + vertex2.x + vertex3.x)/3
和 centerY = (vertex1.y + vertex2.y + vertex3.y)/3
计算从中心点到每个用户点的所有 Angular 。您可以使用 Math.atan2( (vertex1.y-centerY), (vertext1.x-centerX) )
... 对 vertex2 和 vertex3 执行此操作。
按照#2 中计算的 Angular 对点进行升序排序。
这组 3 个点是红色三 Angular 形的顶点。
第三部分:使用第二部分中的顶点将新的红色 div 样式化为三 Angular 形
实用程序
这是一个找到 2 条线段(如果有的话)的交点的 javascript 函数:
// Get interseting point of 2 line segments (if any)
// Attribution: http://paulbourke.net/geometry/pointlineplane/
function line2lineIntersection(p0,p1,p2,p3) {
var unknownA = (p3.x-p2.x) * (p0.y-p2.y) - (p3.y-p2.y) * (p0.x-p2.x);
var unknownB = (p1.x-p0.x) * (p0.y-p2.y) - (p1.y-p0.y) * (p0.x-p2.x);
var denominator = (p3.y-p2.y) * (p1.x-p0.x) - (p3.x-p2.x) * (p1.y-p0.y);
// Test if Coincident
// If the denominator and numerator for the ua and ub are 0
// then the two lines are coincident.
if(unknownA==0 && unknownB==0 && denominator==0){return(null);}
// Test if Parallel
// If the denominator for the equations for ua and ub is 0
// then the two lines are parallel.
if (denominator == 0) return null;
// If the intersection of line segments is required
// then it is only necessary to test if ua and ub lie between 0 and 1.
// Whichever one lies within that range then the corresponding
// line segment contains the intersection point.
// If both lie within the range of 0 to 1 then
// the intersection point is within both line segments.
unknownA /= denominator;
unknownB /= denominator;
var isIntersecting=(unknownA>=0 && unknownA<=1 && unknownB>=0 && unknownB<=1)
if(!isIntersecting){return(null);}
return({
x: p0.x + unknownA * (p1.x-p0.x),
y: p0.y + unknownA * (p1.y-p0.y)
});
}
关于javascript - 检测两个重叠的三 Angular 形并用 javascript 为重叠部分着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31923213/
我有一个Perl脚本,要求用户输入密码。当用户键入字符时,我该如何仅回声“ *”代替用户键入的字符? 我正在使用Windows XP / Vista。 最佳答案 您可以玩Term :: ReadKey
This question already has answers here: How to urlencode a querystring in Python? (13个回答) 7年前关闭。 我正在
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 7 年前。 Improve t
我希望能够检测 h1 中的“/”标签,并将其替换为 ,其中.slash将充当分隔符。 var div = $('h1'); div.html(div.html().replace(/\//g, '/
我是一名 Java 初学者,目前正在寻找一种分割字符串的方法 message根据分隔符 (.) 划分为子字符串。理想情况下,我有单个句子,并且我想将每个句子包装在 HTML 标签中,即。 e. 。
MySql:我的产品表设置如下: pg_id |页面名称 1 |披萨馅饼 2 | child 菜单 Php:在循环遍历 MySQL 表中的记录时回显 html。 "; ?> 我
我正在尝试一次读取一个文本文件并将每一行打印到终端窗口。我正在使用 g++ 在 mac 上编译,例如 g++ cpp3.cpp -o cpp3。 文本文件如下所示: 20100000001 20100
这个问题在这里已经有了答案: sed fails with "unknown option to `s'" error [closed] (1 个回答) 关闭 7 年前。 我有个小问题。 我尝试用文
我有一个非常具体的问题。我正在使用 Debian。我有一个 FTP 文件夹,应用程序将在其中上传 pdf 文件,该文件将存储在 ftpfolder/EMAIL_ADDRESS 中,文件名将是 CURR
我尝试使用其 before 和 after 值的 means 填充 NaN 单元格。 type date v1 v2 0 a 2018-09 215
我在上述模拟中使用 SHM 的标准微分方程,a = -w^2*x。我正在使用 Python,并以 odeint 作为求解器。尽管对其进行了多次编辑,我仍然将输出视为直线而不是正弦曲线。代码是: fro
System.out.print("Enter the message to encrypt: "); message = s.next().toString(); // this mess
我有一个主要的 LinearLayout ,在 main.xml 文件中,在 Activity 中设置 ( setContentView )。入主LinearLayout我想添加 1-X 自定义 Li
并用括起来是否安全?
一些用户生成的文本(可能包含脚本/代码)将向公众展示。如果我过滤掉所有 和标记并用 将结果文本括起来和 ,用户提交的脚本有机会被执行吗? 请给我一个如何破解这个保护方案的例子。 最佳答案 Is it
{abc def ghi} 我已经通过在比较它是否是 { 或 } 之前先跨度包装所有字符来完成此操作。但这太慢了,我需要反转该过程,是否可以获取相对于父 div 的 cha
我想创建一个自定义 UITabBarItem 并使用 xib 文件设置其 UI,就像常规 UIView 一样。 我尝试在 UITabBarItem 上创建一个子类,但创建 xib 文件的选项不可用。
我有以下 HTML 结构: Text 1 Text 2 Text 3 Text 4 Text 5 我想找到一个包含“4”
我正在逐字创建着色工具。基本上用户可以从单词中选择几个字母并将它们分开着色,因此一个单词可以有 2 种或更多颜色。 为了跟踪所有单词,它们都有 ID,我想知道我怎么知道选择了哪些字母以及所选单词有哪些
我是 Python 的新手。我确实有一个包含单词列表的文件。它们包含丹麦字母 (ÆØÅ),但 re.compile 不理解这些字符。该函数按每个 ÆØÅ 拆分单词。文本是从 Twitter 和 Fac
C#如何在字符串中找到多余的)或(括号,并替换为@ 示例输入 )(more))) ((((more))) ((((more)) (about)((index)(more))) (about)((ind
我是一名优秀的程序员,十分优秀!