• Advertisement

Archived

This topic is now archived and is closed to further replies.

How long is this line?

This topic is 5779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm going to use this when making some strange texture effects and i need a way to find out how long a line is in an object like that one posted under this text:. If i have one of theese: .100.pixels. ....._____.... .../.........\... ../~~~~~\.. <--- ./________\. .200.pixels. How can i find out how long the "~" line is in pixels if i know hot far away the "~" line is away from one of the sides? Maby this don't make any sense but i'm not that good at english... Can you help me? [edited by - Andos on April 18, 2002 11:23:49 AM] [edited by - Andos on April 18, 2002 11:24:09 AM] [edited by - Andos on April 18, 2002 11:24:25 AM]

Share this post


Link to post
Share on other sites
Advertisement
Find the angle and use trig function to find the position of the intersection between the / and \ lines and the ~~~ line.
Then, find the distance between those two points.

Out of curiosity, what are you doing?

----------------
Blaster
Computer game programmer and part time human being
Strategy First - http://www.strategyfirst.com
BlasterSoft - http://www.blastersoft.com

Share this post


Link to post
Share on other sites
Can''t this be used?:
LengthLine1-(((LengthLine1 - LengthLine2) / 100 ) * ( ( YofLine / DistanceBetweenLine1&2) * 100 ))

I''m trying to make a wierd software texture rendering...

Share this post


Link to post
Share on other sites
L = (L2-L1)*t + L1 where t goes from zero (L1) to one (L2).
In your case t = Y/distance(L1,L2)

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI's STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...


[edited by - Fruny on April 18, 2002 2:20:25 PM]

Share this post


Link to post
Share on other sites
You mean:

L: Length of the line I try to find

L1: Line 1

L2: Line 2

t: Y or X / with the distance between L1 & L2

Is this correct?

Share this post


Link to post
Share on other sites
Yup, that''s called linear interpolation.

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...

Share this post


Link to post
Share on other sites
But can my other formula also be used?
In code it would maby look like this:

float
LengthLine1, LengthLine2, LENGTHOFUNKNOWNLINE

float
YofUnknownLengthLine, Distance, difference

float
YofLine1, YofLine2

//finish floating ;-)

Start loop

LengthLine1=200

LengthLine2=100

YofLine1=0

YofLine2=100

YofUnknownLengthLine=50

Diffecence=LengthLine1 - LengthLine2

Distance= YofLine2 - YofLine1

LENGTHOFUNKNOWNLINE= LengthLine1-((difference/100)*((YofUnknownLine / distance)*100))

stop loop

Share this post


Link to post
Share on other sites
((Base - Top) * .5) + Top

That should do it. Assuming that the "~" line is half the distance between the top and bottom.

I sure hope this world isn't one big joke, because I don't get it.

[edited by - VisualB4BigD on April 21, 2002 5:16:54 AM]

Share this post


Link to post
Share on other sites
Simply speaking, find the equation for each line, the height off the base, and plug in that value to each line equations to get the point on each line. Like someone said, linear interpolation.

Share this post


Link to post
Share on other sites
The original poster mentions the line length in pixels. That is not the geometric length of the line. In pixels, the length of a line running from coordinates (x1,y1) to (x2,y2) is simply max (abs(x2 - x1), abs(y2 - y1)).

Share this post


Link to post
Share on other sites

0,0
.....100.....
...I_____....
.../..Y..\...
../~~~|~~~\.. <---
./____X____\.
.....200.....
x,y


lets call the length of the ~ line A;
I is the y start of the 100px line

Ok, so if you know how long eatch of those two lines are.
If you know X and Y.
X = length from the 200pxl line to the ~ line on the X-axis.
Y = length from the 100pxl line to the ~ line on the X-axis.

ok, since you know those two, you know the distance betwine thw two known lines.

Lets call the distance Z;
Z = |X-Y| or abs(X-Y)

now you can splne it together.

So if Z == X, then A = 200
elseif Z == Y, then A = 100
else A = 100+(Y-I/X-Y)*100








ok, i dont know what i just said

[edited by - aftermath on April 24, 2002 6:42:18 AM]

Share this post


Link to post
Share on other sites

  • Advertisement