View Full Version : math problem
svenip 01-27-2003, 11:07 AM this is not a maya specific prob but maybe we have a math guru here :)
well, i have two points in 3d space. now i wanna create a third point in space which lies on the same line which is build up by the two points. so thin about two points connected by one line. now stretch the line to infinity. then i wanna calculate a new point with a specific distance from the second point, lying on this infinite line.
anyone ???
|
|
dwalden74
01-27-2003, 01:10 PM
hehe..I´ve also dealt with this problem, and here´s how I solved it:
Create a joint at each point A and B. Now orient the first joint with xyz (joint -e -oj xyz), so now it´s x is aiming towards the next joint. Now you´ve got a straight line between A and B, and the tx value of the second joint represents the distance in space along that line. So just use setAttr to put the joint at a specific distance, and use xform to query its worldspace position.
Hope this helps. If anyone has an easier way of doing this I´d be interested in hearing it....
:beer:
David
svenip
01-27-2003, 01:20 PM
good way :) i really like the idea. but whatever i will do it by math and i just found the math solution. at least i think :)
i'll let you know then :)
btw : i have a very good idea for something to programm. if you're interested in , send me a mail i could describe what i really wanna do.
svenip
01-27-2003, 02:05 PM
ok i gave up on the math thing. i will use your idea i think.
math sucks :)
alexx
01-27-2003, 02:11 PM
that one should do:
you have two points A and B that build upt the direction.
to get that one you subtract B from A.
multiplying the result changes the length and adding the coordinates from point A moves the result to start on A..
cheers
alexx
alexx
01-27-2003, 02:12 PM
like that..
svenip
01-27-2003, 02:17 PM
also very clever :)
but has oneproblem if someone freezes the transform or parent it or something.
but still wow
alexx
01-27-2003, 02:30 PM
of course you should better write a script that does the same and the use xform to query the translation values..
that will make it error proof..
using hypershade was just more visual ;)
cheers
alexx
dwalden74
01-27-2003, 02:55 PM
Alexx´s way is better than mine :annoyed: dohh!!! Anyway, thanks, that´s good to know.
:applause:
David
dwalden74
01-27-2003, 03:13 PM
BTW, while we´re on the subject, I´ve got a quick question: Every time I have to declare a vector variable, I always start off with a float array querying, for example, worldspace translation. Then I put this into my vector, like this:
float $posA[] = `xform -q -ws -t objA`;
vector $vectA = <<$posA[0], $posA[1], $posA[2]>>;
Is there a faster way of declaring the vector without having to deal with the float array first?!?
:beer:
David
danyrey
01-27-2003, 03:48 PM
Simple Vector Algebra:
Get the Entry Vector for the line (Point 1).
Calculate the direction vector for the line (Point 2 - Point 1).
Normalize the directional vector (calculate the length of the directional vector and divide every component of the directional vector with it).
Point 3 = Point 1 + directional Vector * distance Factor
If distance Factor is 1, Point 3 is exactly one unit away from point 1 towards point 2.
:shrug:
Originally posted by svenip
this is not a maya specific prob but maybe we have a math guru here :)
well, i have two points in 3d space. now i wanna create a third point in space which lies on the same line which is build up by the two points. so thin about two points connected by one line. now stretch the line to infinity. then i wanna calculate a new point with a specific distance from the second point, lying on this infinite line.
anyone ???
alexx
01-27-2003, 03:48 PM
not that i would know of..
xform acts kinda like stupid, since it expects and returns always 3 seperate numbers :(
dwalden74
01-27-2003, 04:12 PM
Yeah, I always thought it was strange that quering the position returns a 3-number array instead of a vector...
:wip:
David
alexx
01-27-2003, 04:14 PM
Originally posted by danyrey
Simple Vector Algebra:
Get the Entry Vector for the line (Point 1).
Calculate the direction vector for the line (Point 2 - Point 1).
Normalize the directional vector (calculate the length of the directional vector and divide every component of the directional vector with it).
Point 3 = Point 1 + directional Vector * distance Factor
If distance Factor is 1, Point 3 is exactly one unit away from point 1 towards point 2.
:shrug:
so i must be right, since he posted the same solution a second time :applause:
danyrey
01-27-2003, 05:18 PM
:beer: :D
Haven't read the previous posts too thoroughly.
However, if you need a precise placement you should normalize the directional vector so that the distance factor equals the distance between point 1 and point 3.
For the vector problem -->Saves you one line in your scripts but may look more cryptic:
global proc vector far2vec(float $array[])
{
return << $array[0], $array[1], $array[2] >>;
}
global proc vector iar2vec(int $array[])
{
return << $array[0], $array[1], $array[2] >>;
}
vector $vecA = far2vec (`xform -q -ws -t objA`);
CGTalk Moderation
01-14-2006, 06:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.