473,395 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Interesting Geometry Problem - IQ of 140+ Required :-)

//Shrinks the specified polygon by one pixel (in any relevant direction)
//so that the shrunken polygon sits exactly within the original (specifed)
polygon.
public void Point[] ShrinkPolygon(Point[] polygon)
{
//How do I do this?
}
Sep 24 '06 #1
6 2013
//Shrinks the specified polygon by one pixel (in any relevant direction)
//so that the shrunken polygon sits exactly within the original (specifed)
polygon.
public void Point[] ShrinkPolygon(Point[] polygon)
{
//How do I do this?
}

Take this to comp.graphics.algorithms
Sep 24 '06 #2
//Shrinks the specified polygon by one pixel (in any relevant direction)
//so that the shrunken polygon sits exactly within the original (specifed)
polygon.
public void Point[] ShrinkPolygon(Point[] polygon)
{
//How do I do this?
}

You start by finding the 'middle' of the polygon. Add all X-values up and
divide by the number of values. Add all Y-values up and divide by the number
of values.

Compose a System.Drawing.Drawing2D.Matrix object that translates the points
to the origin, Scale() it in both directions by, say, 0.99 and translate it
back to its original position
Sep 24 '06 #3
On Sun, 24 Sep 2006 00:16:01 -0700, "John Smith" <js****@nowhere.com>
wrote:
>//Shrinks the specified polygon by one pixel (in any relevant direction)
//so that the shrunken polygon sits exactly within the original (specifed)
polygon.
Impossible in the general sense because purely mathematical
calculations won't be pixel-precise. You will have to draw the entire
polygon outline and then take the first line of pixels inside.

My Tektosyne library has a Polygon class that can do floating-point
transformations on regular polygons if you want to try that:
http://www.kynosarges.de/Tektosyne.html
--
http://www.kynosarges.de
Sep 24 '06 #4
John Smith wrote:
//Shrinks the specified polygon by one pixel (in any relevant
direction) //so that the shrunken polygon sits exactly within the
original (specifed) polygon.
public void Point[] ShrinkPolygon(Point[] polygon)
{
//How do I do this?
}
You haven't provided enough information. Is the polygon displayed in
2D or 3D? Is there an orthogal projection of the polygon on the screen
or not?

if it's an orthogonal projection in 2D, you also could have done it
(translate the x / y of the vertices passed in towards the center of
it) so I guess it's not orthogonal in 2D ;).

If it's a problem which means that you want to end up with a polygon
P' which is exactly 1 pixel inside polygon P in _pixelspace_ (thus
after translation), you've to first calculate the end polygon of P in
pixelspace, thus after translation, then do a subtract towards the
center, and then use an inverse matrix to get to the original polygon.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Sep 24 '06 #5
On Sun, 24 Sep 2006 00:16:01 -0700, "John Smith" <js****@nowhere.com>
wrote:
>//Shrinks the specified polygon by one pixel (in any relevant direction)
//so that the shrunken polygon sits exactly within the original (specifed)
polygon.
public void Point[] ShrinkPolygon(Point[] polygon)
{
//How do I do this?
}
Unless you know in advance the resolution that the polygon will be
drawn at, this cannot be done. It might be possible in an idealised
pixellated surface, iff you know exactly which pixels are filled in
when drawing a line (say). You could then decide according to some
scheme or other which pixels counted as "inside" and which not (this
isn't as easy a choice as a first inspection might show). If you were
to repeat the algorithm, the pixels filled in would get less and less
like a polygon as you approached the centre.

In other words, not a trivial problem at all, and one which I suspect
you would do better to solve another way.
Sep 24 '06 #6
Thanks to everyone for their answers. I guess it's an even harder problem
than I anticipated since I have no control of how the pixels are painted
between any two points.
Sep 25 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jon | last post by:
Hello all, I'm certain this question has been asked before; I was unsure what terms to search for within the newsgroup archive to find the proper answer I wanted. Hopefully someone can point me...
7
by: Maxim Shemanarev | last post by:
I'd like to announce my project called Anti-Grain Geometry. http://www.antigrain.com Anti-Grain Geometry (AGG) is an Open Source, free of charge graphic library, written in industrially standard...
14
by: G Patel | last post by:
Pg. 140 of K&R2 shows an example of mutually referential structure declarations... struct t { struct s *p; }; struct s {
3
by: Zorpiedoman | last post by:
I just discovered the following: chr(140) = "OE" chr(156) = "OE" chr(198) = "AE" chr(222) = "TH" chr(223) = "SS" chr(230) = "AE" chr(254) = "TH"
3
by: Otavio Macedo | last post by:
Hi, I am working with MySQL 4.1 and I got a table with a point field. I need to do an "offset" in all the points, that is, adding some deltaX to the X coordinate and a deltaY to the Y...
10
by: Fernando Cacciola | last post by:
Hi, I was initially benchmarking inlinine capabilities of C# in VS 2005 while I stumble on the following surprising results. Please take a look at the following complete sample (you can just...
7
by: Chris | last post by:
Hi, If a user resizes a Toplevel window, or I set a Toplevel's geometry using the geometry() method*, is there any way to have the geometry reset to that required for all the widgets? I think...
2
by: =?Utf-8?B?QXRoZW5hQw==?= | last post by:
Hi, I have tried to draw a big long curve line with more than 10 thousands data sample using Geometry in WPF, and put it into the Scrollviewer. But the performace for scrolling is so poor. Does...
12
by: gsal | last post by:
What would be the easiest way to go about offering 3D graphics for the purpose of rendering geometry? Suppose engineers (my co-workes) have to design some enclosure, nozzle, bracket, or whatever...
3
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, do you know an URL for me where to find a sample for an abstract Geometry class, where classes like Point, Line, Area are inherited. This sample should explain OOP (what is inheritance,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.