POV-Ray : Newsgroups : povray.general : Point along a line. Server Time
17 Nov 2024 01:14:18 EST (-0500)
  Point along a line. (Message 1 to 7 of 7)  
From: BorisW37
Subject: Point along a line.
Date: 18 Jul 2003 19:05:01
Message: <web.3f187c7a5afdf36ca6ac136d0@news.povray.org>
If i have 2 points A <x1,y1,z1> and B <x2,y2,z2>, how do i find coordinates
of point C <x3,y3,z3> which lies on the line AB, distance D from point A?

Thank you,

Boris.


Post a reply to this message

From: Tim Nikias v2 0
Subject: Re: Point along a line.
Date: 18 Jul 2003 19:25:03
Message: <3f1881cf$1@news.povray.org>
That's either
vnormalize(B-A)*D+A
or
-vnormalize(B-A)*D+A
depending on which direction you're thinking of. The first
will either move towards or pass B when D is either smaller
or larger than the distance from A to B,
the second will move away from A and B on the line.

Now that's POV-Code, if you want the actual formula
to do it by hand, you can easily look up vnormalize in
the docs or search the web for normalizing vectors (which
is actually just dividing a vector by its length, which
can be calculated by taking the square-root of the addition
of each component (x, y, and z) squared...
That'd be:
square_root( x*x + y*y + z*z)

That isn't POV-Code, its Pseudo-Code to aid in understanding
the complicated sentence above. :-)

-- 
Tim Nikias v2.0
Homepage: http://www.digitaltwilight.de/no_lights


> If i have 2 points A <x1,y1,z1> and B <x2,y2,z2>, how do i find
coordinates
> of point C <x3,y3,z3> which lies on the line AB, distance D from point A?
>
> Thank you,
>
> Boris.
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.501 / Virus Database: 299 - Release Date: 14.07.2003


Post a reply to this message

From: BorisW37
Subject: Re: Point along a line.
Date: 18 Jul 2003 19:30:01
Message: <web.3f18821015c57b22a6ac136d0@news.povray.org>
BorisW37 wrote:
>If i have 2 points A <x1,y1,z1> and B <x2,y2,z2>, how do i find coordinates
>of point C <x3,y3,z3> which lies on the line AB, distance D from point A?
>
>Thank you,
>
>Boris.
>

I got it:
First find D=distance between A and B
D=sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)
then
x3=x1+d/D(x2-x1)
y3=y1+d/D(y2-y1)
z3=z1+d/D(z2-z1)

but now i have another question, if I have a vector named my_vector
# declare my_vector=<1,2,3>;

how do i find individual values of x,y and z
so that i could find
#declare my_vector_X=.....; (shoud be 1)
#declare my_vector_Y=.....; (shoud be 2)
#declare my_vector_Z=.....; (shoud be 3)


Post a reply to this message

From: Christopher James Huff
Subject: Re: Point along a line.
Date: 18 Jul 2003 19:31:38
Message: <cjameshuff-53B49B.18254818072003@netplex.aussie.org>
In article <web.3f187c7a5afdf36ca6ac136d0@news.povray.org>,
 "BorisW37" <Bor### [at] yahoocom> wrote:

> If i have 2 points A <x1,y1,z1> and B <x2,y2,z2>, how do i find coordinates
> of point C <x3,y3,z3> which lies on the line AB, distance D from point A?

vnormalize(B - A)*D + A

Find a vector pointing in the direction of the line (B-A), normalize it 
so its length is 1, scale it by the desired distance, and add it to the 
first point of the line. If you leave out the vnormalize(), D acts as 
the percentage (as a fractional value in the range [0, 1]) of the 
distance from A to B, rather than the absolute distance in units.

Or if you are just looking for the midpoint, (A + B)/2 will work.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Point along a line.
Date: 18 Jul 2003 19:41:00
Message: <cjameshuff-D41A03.18351018072003@netplex.aussie.org>
In article <web.3f18821015c57b22a6ac136d0@news.povray.org>,
 "BorisW37" <Bor### [at] yahoocom> wrote:

> how do i find individual values of x,y and z

You're making it overly difficult. POV has features for making this kind 
of math easier, the best ways to do it in POV have been explained in 
other replies. You might want to look through math.inc, it has some 
macros and functions that themselves may be useful to you as well as 
showing you what you can do. To answer your question, you can access the 
components with the dot syntax: MyVector.x, MyVector.y, etc. There are 
more dot operators for various situations, this feature is fully 
described in the manual, along with the other built-in vector math 
functions.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Steve Martin
Subject: Re: Point along a line.
Date: 19 Jul 2003 08:02:19
Message: <3f19334b@news.povray.org>
BorisW37 wrote:
> If i have 2 points A <x1,y1,z1> and B <x2,y2,z2>, how do i find coordinates
> of point C <x3,y3,z3> which lies on the line AB, distance D from point A?

x3 = x1 + D * (x2 - x1)

assuming 0 <= D <= 1 (in other words,
assuming D is normallized).

Repeat for y and z.



-- 
Steve Martin, CPBE CBNT


Post a reply to this message

From: JC (Exether)
Subject: Re: Point along a line.
Date: 23 Jul 2003 08:30:41
Message: <3F1E7FEE.1000002@spam.fr>
BorisW37 wrote:
> BorisW37 wrote:
> 
>>If i have 2 points A <x1,y1,z1> and B <x2,y2,z2>, how do i find coordinates
>>of point C <x3,y3,z3> which lies on the line AB, distance D from point A?
>>
>>Thank you,
>>
>>Boris.
>>
> 
> 
> I got it:
> First find D=distance between A and B
> D=sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)
> then
> x3=x1+d/D(x2-x1)
> y3=y1+d/D(y2-y1)
> z3=z1+d/D(z2-z1)
> 
> but now i have another question, if I have a vector named my_vector
> # declare my_vector=<1,2,3>;
> 
> how do i find individual values of x,y and z
> so that i could find
> #declare my_vector_X=.....; (shoud be 1)
> #declare my_vector_Y=.....; (shoud be 2)
> #declare my_vector_Z=.....; (shoud be 3)
> 

When you have vector V, you access its coordinates with V.x, V.y and 
V.z, but it's usually better to use vectors in your formulas.

JC


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.