Home > Back-end >  O master
O master

Time:11-22

Ask a question: is there are two not segments (intersect or disjoint), then one segment of an endpoint scale to their line of intersection,
JavaScript code, seek a solution,

CodePudding user response:

This is what the devil algorithm,

CodePudding user response:

Online squat down a great spirit

CodePudding user response:

L1 object {A (x, y), B (x, y)}, L2 object {A (x, y), B (x, y)}, two rules are defined with the A and B line, then A point of two objects at the same time, the x coordinate of the point object B + + or -, until at the same time there is A or B, same back at this time of L1 and L2,

CodePudding user response:

What things

CodePudding user response:

 var canvas=document. GetElementById (' mycanvas') 
Var context=canvas. GetContext (' 2 d ')
//AX1 AY1 and AX2 AY2 is a line BX1 BY1 and BX2 BY2 is a line
//intersection formula baidu for PX PY is intersection
Var l1=(enclosing AX1 - this. AX2)/(enclosing AY1 - this. AY2)
Var l2=(enclosing BX1 - this. BX2)/(enclosing BY1 - this. BY2)
The console. The log (' l1='+ l1)
The console. The log (' l2='+ l2)
Var p y=(enclosing BX1 - this. AX1 - (l2. * this BY1) + (l1 * this. AY1))/(l1 and l2)

Var PX=l1 * PY - l1. * this AY1 + enclosing AX1
The console. The log (' intersection points' + p + ', '+ p y)
The context. The arc (PX, PY, 1, 0, (Math. PI * 360)/180)

The context. MoveTo (enclosing AX1, enclosing AY1)
Context. LineTo (PX, PY)
The context. MoveTo (enclosing BX2, enclosing BY2)
Context. LineTo (PX, PY)

The context. MoveTo (enclosing AX1, enclosing AY1)
The context. LineTo (enclosing AX2, enclosing AY2)
The context. MoveTo (enclosing BX1, enclosing BY1)
The context. LineTo (enclosing BX2, enclosing BY2)
The context. StrokeStyle='red'
The context. Our lineWidth=3
Context. The stroke ()

CodePudding user response:

refer to fifth floor lonely sea response:
 var canvas=document. The getElementById (' mycanvas) 
Var context=canvas. GetContext (' 2 d ')
//AX1 AY1 and AX2 AY2 is a line BX1 BY1 and BX2 BY2 is a line
//intersection formula baidu for PX PY is intersection
Var l1=(enclosing AX1 - this. AX2)/(enclosing AY1 - this. AY2)
Var l2=(enclosing BX1 - this. BX2)/(enclosing BY1 - this. BY2)
The console. The log (' l1='+ l1)
The console. The log (' l2='+ l2)
Var p y=(enclosing BX1 - this. AX1 - (l2. * this BY1) + (l1 * this. AY1))/(l1 and l2)

Var PX=l1 * PY - l1. * this AY1 + enclosing AX1
The console. The log (' intersection points' + p + ', '+ p y)
The context. The arc (PX, PY, 1, 0, (Math. PI * 360)/180)

The context. MoveTo (enclosing AX1, enclosing AY1)
Context. LineTo (PX, PY)
The context. MoveTo (enclosing BX2, enclosing BY2)
Context. LineTo (PX, PY)

The context. MoveTo (enclosing AX1, enclosing AY1)
The context. LineTo (enclosing AX2, enclosing AY2)
The context. MoveTo (enclosing BX1, enclosing BY1)
The context. LineTo (enclosing BX2, enclosing BY2)
The context. StrokeStyle='red'
The context. Our lineWidth=3
The context. The stroke ()

Bosses this resolution

CodePudding user response:

refer to 6th floor inergnil response:
Quote: refer to fifth floor lonely sea response:
 var canvas=document. The getElementById (' mycanvas) 
Var context=canvas. GetContext (' 2 d ')
//AX1 AY1 and AX2 AY2 is a line BX1 BY1 and BX2 BY2 is a line
//intersection formula baidu for PX PY is intersection
Var l1=(enclosing AX1 - this. AX2)/(enclosing AY1 - this. AY2)
Var l2=(enclosing BX1 - this. BX2)/(enclosing BY1 - this. BY2)
The console. The log (' l1='+ l1)
The console. The log (' l2='+ l2)
Var p y=(enclosing BX1 - this. AX1 - (l2. * this BY1) + (l1 * this. AY1))/(l1 and l2)

Var PX=l1 * PY - l1. * this AY1 + enclosing AX1
The console. The log (' intersection points' + p + ', '+ p y)
The context. The arc (PX, PY, 1, 0, (Math. PI * 360)/180)

The context. MoveTo (enclosing AX1, enclosing AY1)
Context. LineTo (PX, PY)
The context. MoveTo (enclosing BX2, enclosing BY2)
Context. LineTo (PX, PY)

The context. MoveTo (enclosing AX1, enclosing AY1)
The context. LineTo (enclosing AX2, enclosing AY2)
The context. MoveTo (enclosing BX1, enclosing BY1)
The context. LineTo (enclosing BX2, enclosing BY2)
The context. StrokeStyle='red'
The context. Our lineWidth=3
The context. The stroke ()

Bosses the parsing age
baidu
  • Related