我有两条线路UV和PQ,与U(15,10)V(50,25)和P(40,10)和Q(30,30)。
和我发现这两个点之间的交叉点。我形成两个线性方程为:
公式1:
的Ux + T(Vx的-UX)= Px活性+ S(QX-Px)的EQ2
我想用C程序来获得T或s的值来解决这些方程。
我用 T 从第二个方程,并在第一个方程取代它得到一个公式来找到秒。但它没有工作了。我如何在程序中解决这个问题?
解决方案 int类型,SA,SB;好吧, SA 是一个整数。
SA = 1 /((Vx的-UX)*(QY-PY) - (QX-Px)的*(VY-UY));由于这些都是整数,你正在做使用整数运算整数的倒数。结果是无穷大,如果整数是零个,一个,如果它是一个,如果它是负一负一和零,如果它是别的。因此, SA 只有三个可能的值,或者你崩溃。
也许你应该考虑不使用整数运算?也许浮动SA; 和 SA = 1.0 /(...
I have two lines UV and PQ, with U(15,10) V(50,25) and P(40,10) and Q(30,30).
and i am finding a point of intersection between these two points. I am forming two linear equations for that:
eq 1:
Ux + t(Vx-Ux) = Px +s(Qx-Px)eq2
I want to solve these equations using C program to get the value of either t or s.
I used the t from second equation and substituted it in first equation to get a formula to find s. But it did not work out. How can I solve this in a program?
解决方案 int s,sa,sb;Okay, sa is an integer.
sa=1/((Vx-Ux)*(Qy-Py)-(Qx-Px)*(Vy-Uy));Since these are all integers, you're taking the reciprocal of an integer using integer math. The result is infinity if the integer is zero, one if it's one, negative one if it's negative one, and zero if it's anything else. So sa only has three possible values, or you crash.
Perhaps you should consider not using integer math? Maybe float sa; and sa = 1.0 / (....
更多推荐
解决方案二线性方程
发布评论