RE: Math question

Date : Mon, 6 Feb 2006 17:26:08 -0500
To : <XSI(at)Softimage.COM>
From : Michaël Bentitou <michaelb(at)hybride.com>
Subject : RE: Math question

Wow, it would take me much more than 2 cups of coffee to solve this.

 

-=mb.

 

 

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of Mathieu Leclaire
Sent:
Monday, February 06, 2006 5:09 PM
To: XSI(at)Softimage.COM
Subject: RE: Math question

 

We are talking about vectors here… if you say f(x,y,t) = (x-y)*t+y = p   ->    t = (y-p)/(y-x)   but if x, y and p are vectors, how do you divide 2 vectors? I don’t know… maybe I’m missing something obvious but if I go the long way, here’s what happens:

 

T1: pt0 - pt1 - pt2

T2: pt3 - pt4 - pt5

dx, dy, dz

p

 

eq1

p.x = pt0.x

    + dx(pt1.x - pt0.x)

    + dy(pt3.x

        + dx(pt4.x - pt3.x)

        - (pt0.x

            + dx(pt1.x - pt0.x)))

    + dz(dy(pt5.x - pt2.x) - (pt0.x + dx(pt1.x - pt0.x) + dy(pt3.x + dx(pt4.x - pt3.x) - (pt0.x + dx(pt1.x - pt0.x)))))

 

eq2   

p.y = pt0.y

    + dx(pt1.y - pt0.y)

    + dy(pt3.y

        + dx(pt4.y - pt3.y)

        - (pt0.y

            + dx(pt1.y - pt0.y)))

    + dz(dy(pt5.y - pt2.y) - (pt0.y + dx(pt1.y - pt0.y) + dy(pt3.y + dx(pt4.y - pt3.y) - (pt0.y + dx(pt1.y - pt0.y)))))

   

eq3

p.z = pt0.z

    + dx(pt1.z - pt0.z)

    + dy(pt3.z

        + dx(pt4.z - pt3.z)

        - (pt0.z

            + dx(pt1.z - pt0.z)))

    + dz(dy(pt5.z - pt2.z) - (pt0.z + dx(pt1.z - pt0.z) + dy(pt3.z + dx(pt4.z - pt3.z) - (pt0.z + dx(pt1.z - pt0.z)))))

   

   

from eq1

dz = (p.x - (pt0.x

    + dx(pt1.x - pt0.x)

    + dy(pt3.x

        + dx(pt4.x - pt3.x)

        - (pt0.x

            + dx(pt1.x - pt0.x)))))

     / (dy(pt5.x - pt2.x) - (pt0.x + dx(pt1.x - pt0.x) + dy(pt3.x + dx(pt4.x - pt3.x) - (pt0.x + dx(pt1.x - pt0.x))))))

    

replace dz in eq2

 

p.y = pt0.y

    + dx(pt1.y - pt0.y)

    + dy(pt3.y

        + dx(pt4.y - pt3.y)

        - (pt0.y

            + dx(pt1.y - pt0.y)))

    + ((p.x - (pt0.x

    + dx(pt1.x - pt0.x)

    + dy(pt3.x

        + dx(pt4.x - pt3.x)

        - (pt0.x

            + dx(pt1.x - pt0.x)))))

     / (dy(pt5.x - pt2.x) - (pt0.x + dx(pt1.x - pt0.x) + dy(pt3.x + dx(pt4.x - pt3.x) - (pt0.x + dx(pt1.x - pt0.x)))))))

     *(dy(pt5.y - pt2.y) - (pt0.y + dx(pt1.y - pt0.y) + dy(pt3.y + dx(pt4.y - pt3.y) - (pt0.y + dx(pt1.y - pt0.y)))))

    

p.y = pt0.y + dx*pt1.y - dx*pt0.y + dy*pt3.y + dy*dx*pt4.y - dy*dx*pt3.y - dy*pt0.y - dy*dx*pt1.y + dy*dx*pt0.y

    + ((p.x - pt0.x - dx*pt1.x + dx*pt0.x - dy*pt3.x - dy*dx*pt4.x + dy*dx*pt3.x + dy*pt0.x + dy*dx*pt1.x - dy*dx*pt0.x)

      *(dy*pt5.y - dy*pt2.y - pt0.y - dx*pt1.y + dx*pt0.y - dy*pt3.y - dy*dx*pt4.y + dy*dx*pt3.y + pt0.y + dx*pt1.y - dx*pt0.y))

      / (dy*pt5.x - dy*pt2.x - pt0.x - dx*pt1.x + dx*pt0.x - dy*pt3.x - dy*dx*pt4.x + dy*dx*pt3.x + dy*pt0.x + dy*dx*pt1.x - dy*dx*pt0.x)

 

 

0 = (-p.y + pt0.y) + dx*(pt1.y - pt0.y) + dy*(pt3.y - pt0.y) + dy*dx*(pt4.y - pt3.y - pt1.y + pt0.y)

    + ((p.x - pt0.x) + dx*(-pt1.x + pt0.x) + dy*(-pt3.x + pt0.x) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))

      *((pt0.y - pt0.y) + dx*(-pt1.y + pt0.y + pt1.y - pt0.y) dy*(-pt3.y + pt5.y - pt2.y) + dy*dx*(-pt4.y + pt3.y)))

      / (-pt0.x + dx*(-pt1.x + pt0.x) + dy*(-pt3.x + pt5.x - pt2.x + pt0.x) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))

      

now here is where the headache starts...

 

0 = (-p.y + pt0.y) + dx*(pt1.y - pt0.y) + dy*(pt3.y - pt0.y) + dy*dx*(pt4.y - pt3.y - pt1.y + pt0.y)

    + (                             (p.x - pt0.x)*((pt0.y - pt0.y) + dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + dy*(-pt3.y + pt5.y - pt2.y) + dy*dx*(-pt4.y + pt3.y))

        +                     dx*(-pt1.x + pt0.x)*((pt0.y - pt0.y) + dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + dy*(-pt3.y + pt5.y - pt2.y) + dy*dx*(-pt4.y + pt3.y))

        +                     dy*(-pt3.x + pt0.x)*((pt0.y - pt0.y) + dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + dy*(-pt3.y + pt5.y - pt2.y) + dy*dx*(-pt4.y + pt3.y))

        + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))*((pt0.y - pt0.y) + dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + dy*(-pt3.y + pt5.y - pt2.y) + dy*dx*(-pt4.y + pt3.y))

      )

      / (-pt0.x + dx*(-pt1.x + pt0.x) + dy*(-pt3.x + pt5.x - pt2.x + pt0.x) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))

 

 

0 = (-p.y + pt0.y) + dx*(pt1.y - pt0.y) + dy*(pt3.y - pt0.y) + dy*dx*(pt4.y - pt3.y - pt1.y + pt0.y)

    + ( (p.x - pt0.x)*(pt0.y - pt0.y) + (p.x - pt0.x)*dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + (p.x - pt0.x)*dy*(-pt3.y + pt5.y - pt2.y) + (p.x - pt0.x)*dy*dx*(-pt4.y + pt3.y)

        + dx*(-pt1.x + pt0.x)*(pt0.y - pt0.y) + dx*(-pt1.x + pt0.x)*dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + dx*(-pt1.x + pt0.x)*dy*(-pt3.y + pt5.y - pt2.y) + dx*(-pt1.x + pt0.x)*dy*dx*(-pt4.y + pt3.y)

        + dy*(-pt3.x + pt0.x)*(pt0.y - pt0.y) + dy*(-pt3.x + pt0.x)*dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + dy*(-pt3.x + pt0.x)*dy*(-pt3.y + pt5.y - pt2.y) + dy*(-pt3.x + pt0.x)*dy*dx*(-pt4.y + pt3.y)

        + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(pt0.y - pt0.y) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*dx*(-pt1.y + pt0.y + pt1.y - pt0.y) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*dy*(-pt3.y + pt5.y - pt2.y) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*dy*dx*(-pt4.y + pt3.y)

      )

      / (-pt0.x + dx*(-pt1.x + pt0.x) + dy*(-pt3.x + pt5.x - pt2.x + pt0.x) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))

     

     

0 = (-p.y + pt0.y) + dx*(pt1.y - pt0.y) + dy*(pt3.y - pt0.y) + dy*dx*(pt4.y - pt3.y - pt1.y + pt0.y)

    + ( (p.x - pt0.x)*(pt0.y - pt0.y)

        + dx*((p.x - pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y))

        + dy*((p.x - pt0.x)*(-pt3.y + pt5.y - pt2.y))

        + dy*dx*((p.x - pt0.x)*(-pt4.y + pt3.y))

        + dx*(-pt1.x + pt0.x)*(pt0.y - pt0.y)

        + dx*dx*(-pt1.x + pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)

        + dx*dy*(-pt1.x + pt0.x)*(-pt3.y + pt5.y - pt2.y)

        + dy*dx*dx*(-pt1.x + pt0.x)*(-pt4.y + pt3.y)

        + dy*(-pt3.x + pt0.x)*(pt0.y - pt0.y)

        + dx*dy*(-pt3.x + pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)

        + dy*dy*(-pt3.x + pt0.x)*(-pt3.y + pt5.y - pt2.y)

        + dy*dy*dx*(-pt3.x + pt0.x)*(-pt4.y + pt3.y)

        + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(pt0.y - pt0.y)

        + dy*dx*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)

        + dy*dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt3.y + pt5.y - pt2.y)

        + dy*dy*dx*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt4.y + pt3.y)

      )

      / (-pt0.x + dx*(-pt1.x + pt0.x) + dy*(-pt3.x + pt5.x - pt2.x + pt0.x) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))

     

     

0 = (-p.y + pt0.y) + dx*(pt1.y - pt0.y) + dy*(pt3.y - pt0.y) + dy*dx*(pt4.y - pt3.y - pt1.y + pt0.y)

    + ( (p.x - pt0.x)*(pt0.y - pt0.y)

        + dx*((p.x - pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y))

        + dx*(-pt1.x + pt0.x)*(pt0.y - pt0.y)

               

        + dy*((p.x - pt0.x)*(-pt3.y + pt5.y - pt2.y))

        + dy*(-pt3.x + pt0.x)*(pt0.y - pt0.y)

       

        + dy*dx*((p.x - pt0.x)*(-pt4.y + pt3.y))

        + dx*dy*(-pt1.x + pt0.x)*(-pt3.y + pt5.y - pt2.y)

        + dx*dy*(-pt3.x + pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)

        + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(pt0.y - pt0.y)

       

        + dx*dx*(-pt1.x + pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)

       

        + dy*dy*(-pt3.x + pt0.x)*(-pt3.y + pt5.y - pt2.y)

       

        + dy*dx*dx*(-pt1.x + pt0.x)*(-pt4.y + pt3.y)

        + dy*dx*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)        

       

        + dy*dy*dx*(-pt3.x + pt0.x)*(-pt4.y + pt3.y)

        + dy*dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt3.y + pt5.y - pt2.y)

       

        + dy*dy*dx*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt4.y + pt3.y)

      )

      / (-pt0.x + dx*(-pt1.x + pt0.x) + dy*(-pt3.x + pt5.x - pt2.x + pt0.x) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))

 

 

     

0 = (-p.y + pt0.y) + dx*(pt1.y - pt0.y) + dy*(pt3.y - pt0.y) + dy*dx*(pt4.y - pt3.y - pt1.y + pt0.y)

    + ( (p.x - pt0.x)*(pt0.y - pt0.y)

        + dx*(((p.x - pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)) + (-pt1.x + pt0.x)*(pt0.y - pt0.y))

        + dy*(((p.x - pt0.x)*(-pt3.y + pt5.y - pt2.y)) + (-pt3.x + pt0.x)*(pt0.y - pt0.y))       

        + dx*dy*(((p.x - pt0.x)*(-pt4.y + pt3.y)) + (-pt1.x + pt0.x)*(-pt3.y + pt5.y - pt2.y)

            + (-pt3.x + pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y) + (-pt4.x + pt3.x + pt1.x - pt0.x)*(pt0.y - pt0.y))

        + dx*dx*(-pt1.x + pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y)

        + dy*dy*(-pt3.x + pt0.x)*(-pt3.y + pt5.y - pt2.y)

        + dy*dx*dx*((-pt1.x + pt0.x)*(-pt4.y + pt3.y) + (-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt1.y + pt0.y + pt1.y - pt0.y))        

        + dy*dy*dx*((-pt3.x + pt0.x)*(-pt4.y + pt3.y) + (-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt3.y + pt5.y - pt2.y))

        + dy*dy*dx*dx*(-pt4.x + pt3.x + pt1.x - pt0.x)*(-pt4.y + pt3.y)

      )

      / (-pt0.x + dx*(-pt1.x + pt0.x) + dy*(-pt3.x + pt5.x - pt2.x + pt0.x) + dy*dx*(-pt4.x + pt3.x + pt1.x - pt0.x))

     

…and at this point, I just want to throw myself out the window... but I’m only on the second floor so it would just transfer the pain from the mind to the body.

 

There’s gotta be an easier way to figure this out… maybe using matrix or something? I’m gonna go nuts if I keep going down that route… I’m starting to consider writing a program that’ll solve the equation for me but I just don’t want to. Any suggestion or should I just keep going while hopping I don’t make any mistakes along the way?

 

 

Mathieu

 

 

 

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf Of Halfdan Ingvarsson
Sent: Monday, February 06, 2006 2:55 PM
To: XSI(at)Softimage.COM
Subject: RE: Math question

 

Yay. Linear algebra. Start off by making yourself a large cup of coffee. And then another one.

 

Now then, the basic function you're dealing with is     f(x,y,t) = (x-y)*t+y = p   and its solution in 't' is    t = (y-p)/(y-x)

 

Using that, let's restate your code as an equation using that function, like so:

 

f( f( T2.pt2,T1.pt2,dy), f( f(T2.pt1, T2.pt0, dx), f(T1.pt1, T1.pt0, dx), dy), dz ) = P

 

Now all you've got left to do is to expand the terms and start solving. It's probably best to start with dx, followed by dy and dz.

 

The good thing here is that the x,y and z components of the vectors are all independent and you don't have to think about them when solving the equation(s).

 

The rest I leave as an exercise to you. Good luck!

 

 - ½

-----Original Message-----
From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM]On Behalf Of Mathieu Leclaire
Sent: Monday, 06 February, 2006 13:54
To: XSI(at)Softimage.COM
Subject: Math question

Hey guys, I have a question for the Math experts out there.

 

I place a point p in space depending on the 3 points of 2 triangles and 3 coordinates dx, dy, dz. Let’s say I have T1 and T2, the 2 triangles and each triangle has 3 pts: T1.pt0 would be the first point in T1… I calculate p using the following procedure:

 

iT1.Sub(T1.pt1, T1.pt0).ScaleInPlace(dx).AddInPlace(T1.pt0);

iT2.Sub(T2.pt1, T2.pt0).ScaleInPlace(dx).AddInPlace(T2.pt0);

 

o1.Sub(iT2, iT1).ScaleInPlace(dy).AddInPlace(iT1);

o2.Sub(T2.pt2, T1.pt2).ScaleInPlace(dy).AddInPlace(T1.pt2);

 

p.Sub(o2, o1).ScaleInPlace(dz).AddInPlace(o1);

 

 

…so iT1 and iT2 are the points at dx% between the pt0 and pt1 of T1 and T2. o1 and o2 are the points at dy% between iT1 and iT2 and between the pt2 of T1 and T2. And finally, p is the point at dz% between o1 and o2.

 

So my question is the following: What if I already know p, T1 and T2 and I want to calculate dx, dy and dz… how should I do that?

 

 

Mathieu Leclaire

R&D Programmer

Hybride


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.