1
$\begingroup$

Alright, so I got two points in 3d space, so they have a x,y, and z. Now if the line's y - which I get like so:

Vector3 v = new Vector3();
v = a.subtract(b, v);
v.normalizeLocal();

float cosine = (float) v.dot(v);
float angle = (float) Math.toDegrees(Math.acos( cosine ));

Now I have a third point (the c point), which is inside the line of a and b. now I need to know how to get point a and b to 0 and 1, than I need to find out where c is on the line. my goal is to have something like c.y = b.y - (a.y * c.x and c.z's point on the line (which will be between 0 and 1))

So how do I do this?

  • 2
    Your first order of business is to construct a parametric equation $\mathbf h(t)=(a+bt\quad c+dt\quad e+ft)$ such that $\mathbf h(0)$ corresponds to one endpoint, and $\mathbf h(1)$ corresponds to the other endpoint. (Hint: direction cosines).2010-12-07

1 Answers 1

1

I'm not entirely sure that this answers what you're asking--if not, please comment so that I can revise it.

If you have two points $A$ and $B$, the set of points $P=(1-t)\cdot A+t\cdot B$, where $t$ is a real number, is the line through $A$ and $B$, parameterized with $A=P|_{t=0}$ and $B=P|_{t=1}$.

If you know for sure that $C$ is on the line through $A$ and $B$, then set $C=(1-t)\cdot A+t\cdot B$ and solve for $t$ in any one of the components (if $C$ is in fact on the line, then the value of $t$ will be the same, regardless of which component you use; if $C$ is not on the line, then the value of $t$ will not be the same for each component).

note: edited to fix equation $P=$ in the second paragraph, and correspondingly in the third paragraph.

  • 0
    So the dots are dot products? what are they? also what does P|t=0 mean?2010-12-08
  • 0
    @CyanPrime: The dots are scalar multiplication: $t\cdot(x,y,z)=(tx,ty,tz)$. By $P|_{t=0}$ I meant evaluate $P$ when $t=0$.2010-12-08
  • 0
    Alright, so c = (t * a.x, t * a.y, t * a.z) + (1-t * b.x, 1-t * b.y, 1-t * b.z) And t can be any number I want?2010-12-08
  • 0
    @CyanPrime: For $0$A$ and $B$; for $t<0$ or $t>1$, the point will still be on the line, but not between $A$ and $B$. – 2010-12-08
  • 0
    Does having a different number as t change the outcome? If so, what number should I use to make it between 1 and 0?2010-12-08
  • 0
    @CyanPrime: I'm not sure what you mean. Which pieces of information are you given and what are you trying to find?2010-12-08
  • 0
    I only have the 3 points, A,B, and C. A will always be less than B, and C will always be in between A and B. Lets say A is 300,330,320 and B is 400,432,459, and C is 355,372,399, how can I divide these so that A = 0, B = 1, and C > 0 and C < 1?2010-12-08
  • 0
    @CyanPrime: Hmm... I think I misunderstood the original problem, then, as the point C you gave is not on the line through A and B.2010-12-08
  • 0
    @CyanPrime: Also, note that I edited my answer to swap $t$ and $(1-t)$, as I'd accidentally reversed them.2010-12-08
  • 0
    Huh? but A.x > C.x < B.x, and same for Y and Z2010-12-08
  • 0
    @CyanPrime: If we imagine the 3-space coordinate system with x- and y-axes parallel to the ground and z-axis perpendicular to the ground, C is in the rectangular box with sides parallel/perpendicular to the ground and diagonally-opposite corners at A and B; C is not, however, along the space-diagonal of that box, which is the line through A and B (imagine a string pulled tight between A and B).2010-12-08
  • 0
    Ahhh, alright. so any ideas on how to work with these points than?2010-12-08
  • 0
    @CyanPrime: I'm still not clear on what it is that you need to get from these three points. What is the end goal? (If this is part of a larger problem, perhaps that context would help clarify the question.)2010-12-08
  • 0
    http://pastebin.com/gZrf7H8d This is what I got so far I wanna make it so if the ground is at a angle you move up or down at that angle2010-12-08
  • 0
    @CyanPrime: I suspect that the combination of the code and the overall description of what you're trying to do should be enough to figure out an answer, but between other work and lack of familiarity with the programming constructs involved (I know nothing about programming for 3d graphics, etc.), I can't seem to get my head around it at the moment. If you haven't already, I'd suggest posting your code and the restatement of your question from that last comment on StackOverflow (or perhaps gamedev.stackexchange.com, but I don't know anything about that site).2010-12-08