How long is this line?

Started by
10 comments, last by Andos 22 years ago
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]
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
Can''t this be used?:
LengthLine1-(((LengthLine1 - LengthLine2) / 100 ) * ( ( YofLine / DistanceBetweenLine1&2) * 100 ))

I''m trying to make a wierd software texture rendering...
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]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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?
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...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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
((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]
The "~" line is the line I try to find the length of...
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.

This topic is closed to new replies.

Advertisement