-1

I would appreciate any good advice. I want to determine the inequality sign from the triangular part of the seven places.

https://www.wolframalpha.com/input/?i=x+%E2%88%92+y+%3D+0%2C+x+%2B+y+%E2%88%92+2+%3D+0%2C+3*x+%E2%88%92+y+%E2%88%92+6+%3D+0&lang=ja

https://www.wolframalpha.com/input/?i=x+%E2%88%92+y+%3E%3D+0+%2C+x+%2B+y+%E2%88%92+2+%3E%3D+0%2C++3*x+%E2%88%92+y+%E2%88%92+6+%3C%3D+0&lang=ja

Input: x − y = 0, x + y − 2 = 0, 3*x − y − 6 = 0

I want to convert bellow

Output: x − y >= 0 , x + y − 2 >= 0, 3*x − y − 6 <= 0

mrrclb46z
  • 89
  • 6

2 Answers2

0

One way of doing that is by doing the following steps:

  1. calculate the vertices of the triangle
  2. for each 2 vertices, calculate the line that goes through them
  3. for each vertex, check whether the line of the 2 other vertices is above or below the vertex

STEP 1

You can find the vertices of the triangle by finding the intersection points of every pair of sides:

let's find the intersection point of two lines: ax+by+c=0 and dx+ey+f=0.

the point should satisfy both equations, so:

ax+by=-c
dx+ey=-f

we can remove the y from the first equation by subtracting the second equation multiplied by (b/e). and we get:

(a-(d*b/e))x=-c+(f*b/e) => x=(-c+f*b/e)/(a-(d*b/e))`
dx+ey=-f

and then we can remove the x from the second equation by subtracting the first equation multiplied by d. and we get:

x=(-c+f*b/e)/(a-(d*b/e))
ey=-f-d(-c+f*b/e)/(a-(d*b/e)) => y=(-f-d(-c+f*b/e)/(a-(d*b/e)))/e

so the intersection point is: ((-c+f*b/e)/(a-(d*b/e)),(-f-d(-c+f*b/e)/(a-(d*b/e)))/e)

ugly, I know, but it works :)

STEP 2

now that we have the 3 vertices of the triangle, let's call them (x1,y1),(x2,y2),(x3,y3). the equation of the line that goes through 2 points (a,b) and (c,d) is: ((d-b)/(c-a))x-y-(((d-b)/(c-a))a+b)=0

so the lines are:

((y2-y1)/(x2-x1))x-y-(((y2-y1)/(x2-x1))x1+y1)=0
((y3-y1)/(x3-x1))x-y-(((y3-y1)/(x3-x1))x1+y1)=0
((y3-y2)/(x3-x2))x-y-(((y3-y2)/(x3-x2))x2+y2)=0

STEP 3

If a,b,c are numbers so that b<0 then a point (x',y') is above the line ax+by+c=0 if and only if ax' + by' + c <= 0. so just check the equations we found before: each vertex of the triangle is in the triangle, so the lines inequalities must hold for it, if a vertex is above a side, then all other points in the triangle are above.

Hope you find this answer useful :)

Note: beware of extreme cases, some of the steps don't work for all cases (like when the line is x=0)

atanay
  • 174
  • 10
0

when Line x=not Constant (only diagonal Case)

I try

from sympy import *
var('x y')
def mySympify(myL):
    return sympify(myL.replace('=0',''))
def myDicXY(myDic):
    return myDic.get(x,""),myDic.get(y,"")
def myStr2Ineq(myStr,myLine,x9,y9):
    if myLine.lhs.subs(x,x9).subs(y,y9) < 0 :
       ans = myStr.replace('=0', '<=0')
    else:
       ans = myStr.replace('=0', '>=0')
    return ans
myInput="x-y=0,x+y-2=0,3*x-y-6=0"
print("#",myInput)
myStr=myInput.split(',')
myLine_0=Eq(mySympify(myStr[0]),0)
myLine_1=Eq(mySympify(myStr[1]),0)
myLine_2=Eq(mySympify(myStr[2]),0)
x0,y0=myDicXY(solve([myLine_1,myLine_2],[x,y]))
x1,y1=myDicXY(solve([myLine_2,myLine_0],[x,y]))
x2,y2=myDicXY(solve([myLine_0,myLine_1],[x,y]))
myOutput=   myStr2Ineq(myStr[0],myLine_0,x0,y0) + "," \
          + myStr2Ineq(myStr[1],myLine_1,x1,y1) + "," \
          + myStr2Ineq(myStr[2],myLine_2,x2,y2)
print("#",myOutput)
# x-y=0,x+y-2=0,3*x-y-6=0
# x-y>=0,x+y-2>=0,3*x-y-6<=0
mrrclb46z
  • 89
  • 6