192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Mid-point for a 4 sided polygon AKA point equidistant from 4 points [RESOLVED]
I have a coordinate system defined as follows:
TL, TR, BL and BR are the top left, top right etc. points of my polygon.
The X-axis runs from along the top edge and the Y-axis runs across the polygon, from the top edge to the bottom edge.
Hopefully the diagram kindly provided by kedaman shows this clearly. In the drawing X is 0.3 and Y is 0.8
This works well, as i change the vertex points a point defined in the polygon coordinate space moves as expected.
The trouble is that DirectX texture-maps only triangles. As a result i've split all my polygons into 2 triangles, with the diagonal running from the top right to the bottom left.
The upshot of all this is that my points on my polygon don't match the rendered texture as the vertices move. Also, when the polygon is stretched it doesn't look right, since one triangle could be very stretched, but not the other.
What i think may work is splitting the polygon into 4 triangles, creating a centre point in the middle of the polygon.
Currently what i do is get the intersection between the 2 diagnoals of the polygon and treat that as the centre. This doesn't work, or look good.
What i think might work is to position the centre point such that it is an equal distance from all 4 vertices of my polygon.
This is what i need help with. Currently i'm thinking that i do it by working out 2 lines (one for each pair of lines) such that all points on the lines are equidistant from 2 points. I then find the intersection and that will be the point that's equidistant from all 4. I'm not sure if this is right though, so if anyone know how to do this another way that's fine.
Thinking about it, i'm not sure that it is possible to get a point equidistant from 4 points, however i have a feeling that the above method may look good anyway.
I'm not sure quite how to approch this problem, so any help would greatly be appreciated.
Last edited by SLH; Mar 21st, 2005 at 10:20 AM.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Re: Mid-point for a 4 sided polygon AKA point equidistant from 4 points
LOL, after trying the method of intersecting locus' it was obvious that it wasn't gonna work.
I tried something nice and simple - the average of all vertices. This works perfectly!
Hmm, maybe i should give myself some reputation points!
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Re: Mid-point for a 4 sided polygon AKA point equidistant from 4 points [RESOLVED]
Originally Posted by Ecniv
ahh ok.. I was going to suggest that you use the 3d points to get the 2d points then find the center from there
Your way is probably faster
Not too sure what you mean, would you mind elaborating, since it might be useful for future reference?
BTW, i'm working using 2D coordinates anyway, so it wouldn't apply.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Re: Mid-point for a 4 sided polygon AKA point equidistant from 4 points [RESOLVED]
Note that if you have a concave polygon, the average point might fall outside it, for instance a polygon looking like the head of an arrow.
btw, if the polygon is concave, then my earlier method wont work either, since a line could not be straight without falling outside.
Last edited by kedaman; Mar 21st, 2005 at 09:00 PM.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Re: Mid-point for a 4 sided polygon AKA point equidistant from 4 points [RESOLVED]
Ooo, hadn't thought of that, although it shouldn't matter since the polygon shouldn't get that warped (and if it does the polygon wouldn't render properly anyway).
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Re: Mid-point for a 4 sided polygon AKA point equidistant from 4 points [RESOLVED]
I just discovered something else, my method fails miserably to draw straight diagonals. On the other hand I think there must be a way to render them effectively anyway, if you only could specify its 3d coordinates
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
Posts
3,051
Re: Mid-point for a 4 sided polygon AKA point equidistant from 4 points [RESOLVED]
That's the thing though, for my application it makes no sense to have 3D coordinates, since the user (and program) is working in 2D space only.
I think the problem stems from the fact that DX renders triangles a standard way, and i'm trying to allow the user to manipulate quads (4-sided polygons) and trying to get them to look right, when really they won't in some cases.
This isn't critical though, since these polygons are gonna be pretty small, and any warping will be minimal. Plus this isn't the main point of my application!
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons