質問

思い描いているのか、ウィンドウで、いを行う事によって、ユーザのドラッグしするようにしてください。なので、私のラインが定義される二つのポイント:(x1,y1)と点(x2,y2).今はいただきたいと思い"キャップ"のアイコンによる垂直ラインでひとりひとりの終点です。のキャップはNとするピクセルの長さです。

このように描く"のキャップ"線の終点(x1,y1)、まつとなる垂直ラインがそのポイントN/2画素から離れた点(x1,y1).

だからどうやって計算ポイント(x3,y3)を与えるかというニーズにする垂直距離N/2から終点(x1,y1)公知の物のライン、すなわちのラインで定義されるが(x1,y1)と点(x2,y2)?

役に立ちましたか?

解決

必要なものを計算する単位ベクトルが垂直の線分になります。回避をコンピューティングするこの斜面でつながる分割によるゼロます。

dx = x1-x2
dy = y1-y2
dist = sqrt(dx*dx + dy*dy)
dx /= dist
dy /= dist
x3 = x1 + (N/2)*dy
y3 = y1 - (N/2)*dx
x4 = x1 - (N/2)*dy
y4 = y1 + (N/2)*dx

他のヒント

あなただけの評価に直交versorび掛けによりN/2

vx = x2-x1
vy = y2-y1
len = sqrt( vx*vx + vy*vy )
ux = -vy/len
uy = vx/len

x3 = x1 + N/2 * ux
Y3 = y1 + N/2 * uy

x4 = x1 - N/2 * ux
Y4 = y1 - N/2 * uy

らベクトルから2-1-1-3垂直、ドットの製品は0になります。

このようにいつも未知:x1日から3(x13)、yから1~3(y13)

利用のPythagorean定理を提案する内野グループ方程式の方に不思議な現象がいろいろあ.

解決のための各未知の置換による...

このことは、二乗unsquaringのではなく、署名に関連付方程式

決定の符号で発生していると考えること

while x21 is negative, y13 will be positive
while x21 is positive, y13 will be negative
while y21 is positive, x13 will be positive
while y21 is negative, x13 will be negative

知られていポイント1:x1,y1

知られていポイント2:x2,y2)

x21 = x1 - x2
y21 = y1 - y2

知られてい距離-1->3|:N/2

式a:Pythagorean定理

x13^2 + y13^2 = |1->3|^2
x13^2 + y13^2 = (N/2)^2

知られてい角2-1-3:直角

ベクトルを2->1-1>3垂直

2->1点1->3で0

式b:ドットの製品=0

x21*x13 + y21*y13 = 2->1 dot 1->3
x21*x13 + y21*y13 = 0

比b/w x13とy13:

x21*x13 = -y21*y13
x13 = -(y21/x21)y13

x13 = -phi*y13

式a:解決のためのy13との比率

  plug x13 into a
phi^2*y13^2 + y13^2 = |1->3|^2

  factor out y13
y13^2 * (phi^2 + 1) = 

  plug in phi
y13^2 * (y21^2/x21^2 + 1) = 

  multiply both sides by x21^2
y13^2 * (y21^2 + x21^2) = |1->3|^2 * x21^2

  plug in Pythagorean theorem of 2->1
y13^2 * |2->1|^2 = |1->3|^2 * x21^2

  take square root of both sides
y13 * |2->1| = |1->3| * x21

  divide both sides by the length of 1->2
y13 = (|1->3|/|2->1|) *x21

  lets call the ratio of 1->3 to 2->1 lengths psi
y13 = psi * x21

  check the signs
    when x21 is negative, y13 will be positive
    when x21 is positive, y13 will be negative

y13 = -psi * x21

式a:解決のためのx13との比率

  plug y13 into a
x13^2 + x13^2/phi^2 = |1->3|^2

  factor out x13
x13^2 * (1 + 1/phi^2) = 

  plug in phi
x13^2 * (1 + x21^2/y21^2) = 

  multiply both sides by y21^2
x13^2 * (y21^2 + x21^2) = |1->3|^2 * y21^2

  plug in Pythagorean theorem of 2->1
x13^2 * |2->1|^2 = |1->3|^2 * y21^2

  take square root of both sides
x13 * |2->1| = |1->3| * y21

  divide both sides by the length of 2->1
x13 = (|1->3|/|2->1|) *y21

  lets call the ratio of |1->3| to |2->1| psi
x13 = psi * y21

  check the signs
    when y21 is negative, x13 will be negative
    when y21 is positive, x13 will be negative

x13 = psi * y21

凝縮

x21 = x1 - x2
y21 = y1 - y2

|2->1| = sqrt( x21^2 + y^21^2 )
|1->3| = N/2

psi = |1->3|/|2->1|

y13 = -psi * x21
x13 =  psi * y21

私は普通なことが解決で仕事を手にすることが説明で徹底していった強固なも自分の知識.

いようにしたい場合は、sqrt、次の操作を行います:

in: line_length, cap_length, rotation, position of line centre

define points:
  tl (-line_length/2, cap_length)
  tr (line_length/2, cap_length)
  bl (-line_length/2, -cap_length)
  br (line_length/2, -cap_length)

rotate the four points by 'rotation'
offset four points by 'position'

drawline (midpoint tl,bl to midpoint tr,br)
drawline (tl to bl)
drawline (tr to br)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top