POV-Ray : Newsgroups : povray.general : POV-related math question Server Time
5 Aug 2024 12:18:40 EDT (-0400)
  POV-related math question (Message 1 to 9 of 9)  
From: Dan Byers
Subject: POV-related math question
Date: 1 Oct 2002 20:20:03
Message: <web.3d9a3acd610548727c10c2df0@news.povray.org>
go to http://hometown.aol.com/goofygrafx/qa.html (there's a picture
involved)

thanks :)

------------------
dan
http://hometown.aol.com/goofygrafx


Post a reply to this message

From: James Taylor
Subject: Re: POV-related math question
Date: 1 Oct 2002 21:17:42
Message: <3d9a4936@news.povray.org>
maybe this isn't the best way but, solve y=mx+c for each line and then
iterate using newton-rhapson (?) or similar to find intersection point.

jim


Post a reply to this message

From: Niytaan
Subject: Re: POV-related math question
Date: 1 Oct 2002 21:25:16
Message: <3d9a4afc$1@news.povray.org>
If I remember from math correctly:
The math explanation:

Well, since you already know what the points are then you can easily find
the slopes of the two lines. Then simply write up the equation for each line
using:

y = m*x + b

m equals slope, b equals y-intercept, both are easy to find

Then, to find what your x value for the intersection is, solve for x in the
equation:

Line 1        Line 2
m*x + b = m*x + b

Remember that one side of the equation should not be identical to the other.

Then solve for y in one of the equations(y = m*x + b) using your x value
that you just found. You now have your x and y values for the point of
intersection.

Hopefully that is all correct, but I can't make up a macro right now.

"Dan Byers" <nomail@nomail> wrote in message
news:web.3d9a3acd610548727c10c2df0@news.povray.org...
> go to http://hometown.aol.com/goofygrafx/qa.html (there's a picture
> involved)
>
> thanks :)
>
> ------------------
> dan
> http://hometown.aol.com/goofygrafx
>


Post a reply to this message

From: Dan Byers
Subject: Re: POV-related math question
Date: 1 Oct 2002 21:35:02
Message: <web.3d9a4cda9b98c28e7c10c2df0@news.povray.org>
James Taylor wrote:
>maybe this isn't the best way but, solve y=mx+c for each line and then
>iterate using newton-rhapson (?) or similar to find intersection point.
>
>jim
>

umm... I have no idea what you just said... :)

approach it from this angle: imagine I'm a dork whose highest level of math
education was intermediate algebra in college some time ago :)

--------------
dan
http://hometown.aol.com/goofygrafx


Post a reply to this message

From: Dan Byers
Subject: Re: POV-related math question
Date: 1 Oct 2002 21:50:08
Message: <web.3d9a4fef9b98c28e7c10c2df0@news.povray.org>
Niytaan wrote:
>If I remember from math correctly:
>The math explanation:
>
>Well, since you already know what the points are then you can easily find
>the slopes of the two lines. Then simply write up the equation for each line
>using:
>
>y = m*x + b
>
>m equals slope, b equals y-intercept, both are easy to find
>
>Then, to find what your x value for the intersection is, solve for x in the
>equation:
>
>Line 1        Line 2
>m*x + b = m*x + b
>
>Remember that one side of the equation should not be identical to the other.
>
>Then solve for y in one of the equations(y = m*x + b) using your x value
>that you just found. You now have your x and y values for the point of
>intersection.
>

okay, I think I can follow what's happening here, except for that "b equals
y-intercept" part... what is that, exactly?  thanks :)

------------
dan
http://hometown.aol.com/goofygrafx


Post a reply to this message

From: Slime
Subject: Re: POV-related math question
Date: 1 Oct 2002 22:16:02
Message: <3d9a56e2$1@news.povray.org>
> okay, I think I can follow what's happening here, except for that "b
equals
> y-intercept" part... what is that, exactly?  thanks :)


It's the place where, if the line extended infinitely, it would cross the
Y-axis.

It might be easier to use the point-slope form of a line:

y-k = m*(x-h)

where the line passes through the point (h,k) and has slope m. (If you have
two points on a line, such as (a,b) and (c,d), which you do, you can find
the slope (m) via (d-b)/(c-a).)

There may be a problem if it's possible for the lines to be vertical.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

From: Shay
Subject: Re: POV-related math question
Date: 2 Oct 2002 09:38:46
Message: <3d9af6e6@news.povray.org>
Dan Byers <nomail@nomail> wrote in message
news:web.3d9a3acd610548727c10c2df0@news.povray.org...

Here's a no math (on your part) answer:

#local R1 = [one end of red line];
#local R2 = [other end of red line];
#local P1 = [one end of purple line];
#local P2 = [other end of purple line];

#local RedVector = R2 - R1;
#local PurpleVector = P2 - P1;

#local Target = plane {vcross(<0,0,1>, RedVector), R1);
#local Intersection = trace (Target, P1, PurpleVector);

 // trace works *so* fast that this might be as quick
 // as any answer
 // untested


Post a reply to this message

From: Ive
Subject: Re: POV-related math question
Date: 2 Oct 2002 10:37:08
Message: <3d9b0494@news.povray.org>
Hi Dan,

you are talking about *line segments* and not *lines* because a line is infinite and
two lines do always
intersect in case they are not coincident or parallel.
But here is the solution:

Assuming:
we call the red line: line a with the start/end points P1 (x1,y1) and P2 (x2,y2)
and the purple line: line b with the start/end points P3 (x3,y3) and P4 (x4,y4)

the equations are:
Pa = P1 + ua ( P2 - P1 )
Pb = P3 + ub ( P4 - P3 )

with the two unknowns ua and ub,.
... but we can solve this for Pa=Pb because this is the point the lines do intersect:

ua = ((x4-x3)(y1-y3) - (y4-y3)(x1-x3)) / ((y4-y3)(x2-x1) - (x4-x3)(y2-y1))

ub = ((x2-x1)(y1-y3) - (y2-y1)(x1-x3)) / ((y4-y3)(x2-x1) - (x4-x3)(y2-y1))

Note that the two denominators are the same. If the denominator is 0 the
two lines are parallel (and so will not intersect) and if the numerator is also 0
the two lines are coincident.

But you are looking for the intersection and here it is:

x = x1 + ua (x2 - x1)
y = y1 + ua (y2 - y1)

sorry, not finished yet because this is the intersection for the two lines, but
you want to know if the line *segments* do intersect, but this is easy:
if both ua and ub lie in the range of 0 to 1 the two line segments DO intersect
in any other case they miss each other.

so long
-Ive


Post a reply to this message

From: Dan Byers
Subject: Re: POV-related math question
Date: 2 Oct 2002 20:45:06
Message: <web.3d9b920b9b98c28e7c10c2df0@news.povray.org>
Thanks to everyone who responded! :)  I was digging thru my bookshelf
looking for my Java book and I stumbled across my old algebra book.  Inside
were listed a few different ways to solve the intersection of a pair of
linear equations.  I turned that into a macro, and it works! (believe me,
no one was more surprised than I!).  For the curious (or bored), here's the
macro:

#macro LineIntersect( v1Start, v1End, v2Start, v2End)
//-------------------------------------------------------------------
// returns a vector with the point that represents the intersection
// of a pair of lines... assumes Z is zero and that both lines are
// neither parallel, superimposed, or vertical...
//-------------------------------------------------------------------
 #local v1 = v1End - v1Start;
 #local rise1 = v1.y;
 #local run1 = v1.x;
 #local k1 = v1Start.y;
 #local h1 = v1Start.x;

 #local v2 = v2End - v2Start;
 #local rise2 = v2.y;
 #local run2 = v2.x;
 #local k2 = v2Start.y;
 #local h2 = v2Start.x;

 #local run3 = run2 / run1;
 #local myX = (((run2*k2) - (rise2*h2)) - (run2*((run1*k1) - (rise1*h1))/
run1)) / ((run2*rise1/run1) - rise2);
 #local myY = ((run1*k1) - (rise1*h1) + (rise1*myX)) / run1;
 <myX, myY, 0>
#end

--------------
dan
http://hometown.aol.com/goofygrafx


Post a reply to this message

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