Login or Sign Up to become a member!
LessThanDot Site Logo

LessThanDot

A Technical Community for IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Highly Rated Users

Forum
No Posts Rated

Top 50
Given
Received

Forum Statistics

Users
Members:
1592
Members Online:
6
Guests Online:
9

Total Post History
Posts:
80552
Topics:
18446

7-Day Post History
New Posts:
9
New Topics:
1
Active Topics:
7

Our newest member
marykee

Other

FAQ
All times are UTC [ DST ]

Google Ads

LTD Puzzle 2: Regular Pentagon

Mind Boggling Puzzles, to keep that grey matter in shape...
Forum rules
Always post answers in a "Hidecode" tag, so that others have a chance to answer the question too.
Please wait...

LTD Puzzle 2: Regular Pentagon

Postby AlexCuse on Fri Jun 13, 2008 5:07 pm

Given a grid co-ordinate (x,y) as the centre point of a regular pentagon, and the sum of the length of the sides, return the co-ordinates of each point as: "Top", "MidLeft", "MidRight", "BottomLeft", "BottomRight" and the distance from the centre to each of the points.

This should work for any possible position of the centre point, and any length of the sides.

  • All Sides are equal length in a Regular Pentagon
  • x = horizontal scale, y=vertical
  • scale increments can be anything you wish.. mm, cm, inches, feet, etc (doesn't matter) - though only whole units can be used

For added points, make it work for any regular polygon (and even further added points for calculating the area)

<courtesy of damber, its' not my wacky spelling :P />
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5411
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US

Re: Regular Pentagon

Postby Emtucifor on Tue Jun 17, 2008 3:42 am

Code is hidden, SHOW

P.S. I'm not sure what "only whole units can be used" means. Please clarify and I will correct, probably by multiplying to get rid of any decimal point. :)
Last edited by Emtucifor on Tue Jun 17, 2008 5:30 pm, edited 2 times in total.
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA

Re: Regular Pentagon

Postby damber on Tue Jun 17, 2008 10:01 am

Erik - don't worry about the whole numbers thing, it was initially intended to keep things simple, but as the puzzle scope changed it doesn't really make sense to keep it in, so I've edited it out.
a smile is worth a thousand kind words, so smile, it's easy! :-)


CODE: $5
WORKING CODE: $500
PROPERLY DESIGNED & WORKING CODE: Priceless
User avatar
damber
LTD Admin
LTD Admin
LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660
LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660
 
Posts: 3134
Joined: Tue Oct 09, 2007 1:48 pm
Location: North Wales, UK
Unrated

Re: Regular Pentagon

Postby gmmastros on Tue Jun 17, 2008 5:25 pm

VB6 Solution:

Code is hidden, SHOW


Download sample application: Polygon Points
You do not have the required permissions to view the files attached to this post.
-George
User avatar
gmmastros
LTD Admin
LTD Admin
LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616
LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616
LTD Gold - Rating: 1616LTD Gold - Rating: 1616
 
Posts: 2327
Joined: Tue Oct 09, 2007 5:19 pm

Re: Regular Pentagon

Postby SQLDenis on Tue Jun 17, 2008 5:32 pm

ErikE wrote:P.S. I'm not sure what "only whole units can be used" means. Please clarify and I will correct, probably by multiplying to get rid of any decimal point. :)



I don't know how many decimal points you need but sql server has a pi function built in
  1. SELECT PI()
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
 
Posts: 21757
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: Regular Pentagon

Postby Emtucifor on Tue Jun 17, 2008 5:32 pm

George,

I think you've been doing polygon math FAR too long for me to compete with. Good work.

I was thinking last night that my code is flawed because it can accumulate errors as it goes. I was thinking about the problem incorrectly. I should have calculated each point from the center as you did. Then half my variables could be disposed of...
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA
Unrated

Re: Regular Pentagon

Postby AlexCuse on Tue Jun 17, 2008 6:03 pm

Now that I think about it, You missed one thing George:

Given a grid co-ordinate (x,y) as the centre point of a regular pentagon


Shouldn't be too tough though.

Its' not going to win any shortest code contests because I created my own types and enabled them convert between each other, but here goes (anything to liven this thread up a bit). C# on the console

Code is hidden, SHOW
Say what you like about the tenets of National Socialism Dude, at least it's an ethos
User avatar
AlexCuse
LTD Admin
LTD Admin
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021LTD Gold - Rating: 1021
LTD Gold - Rating: 1021
 
Posts: 5411
Joined: Tue Oct 09, 2007 5:26 pm
Location: Pennsylvania, US

Re: Regular Pentagon

Postby Emtucifor on Tue Jun 17, 2008 6:15 pm

SQLDenis wrote:I don't know how many decimal points you need but sql server has a pi function built in
  1. SELECT PI()

I know THAT. :P

1. The Pi() function is very slow.
2. The Pi() function only gives 16 decimal places.
3. The Pi() function's 16th digit is wrong. Not just rounded incorrectly, but wrong any way you look at it.

That's why I didn't use it. Plus, I have Pi memorized to 58 decimal places so typing it out is extremely easy and convenient for me.
God cries a little bit every time someone builds a database.
User avatar
Emtucifor
Guru
Guru
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030LTD Gold - Rating: 1030
LTD Gold - Rating: 1030
 
Posts: 2835
Joined: Fri May 30, 2008 9:30 pm
Location: Bellingham, WA
Unrated

Re: Regular Pentagon

Postby damber on Tue Jun 17, 2008 6:30 pm

OK, here's mine (ASP.NET / C#):

Code is hidden, SHOW


I tested it as the codebehind of an aspx page, but you can easily change to run in the console etc.

It will accept any coordinate for the centre point, number of sides/points, a positive length for the sides and an offset rotation in degrees from north (so you can rotate the polygon).

It will return all the points with Cartesian X, Y and Polar Coordinates as well as the Area, distance from the centre to the edge at the furthest and nearest point and the relevant angles.
a smile is worth a thousand kind words, so smile, it's easy! :-)


CODE: $5
WORKING CODE: $500
PROPERLY DESIGNED & WORKING CODE: Priceless
User avatar
damber
LTD Admin
LTD Admin
LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660
LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660
 
Posts: 3134
Joined: Tue Oct 09, 2007 1:48 pm
Location: North Wales, UK

Re: Regular Pentagon

Postby SQLDenis on Tue Jun 17, 2008 7:43 pm

ErikE wrote:Plus, I have Pi memorized to 58 decimal places so typing it out is extremely easy and convenient for me.




PFFFtttttt, I expected you to have a MotherOfAllValuesOrFunctions table so that you don't have to type it in


BTW, do you know that I have stuff like this "select dateadd(mm, datediff(mm, 0, getdate())-11, 0)" in notes in outlook :-)
User avatar
SQLDenis
LTD Admin
LTD Admin
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
LTD Gold - Rating: 3455LTD Gold - Rating: 3455LTD Gold - Rating: 3455
 
Posts: 21757
Joined: Wed Oct 10, 2007 6:43 pm
Location: Princeton, New Jersey, USA,World, Solar System, Milky Way, Universe and Beyond
Unrated

Re: Regular Pentagon

Postby gmmastros on Tue Jun 17, 2008 8:05 pm

AlexCuse wrote:Now that I think about it, You missed one thing George:

Given a grid co-ordinate (x,y) as the centre point of a regular pentagon


Shouldn't be too tough though.


Yes Alex. It's not that tough. In fact....

Code is hidden, SHOW
-George
User avatar
gmmastros
LTD Admin
LTD Admin
LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616
LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616LTD Gold - Rating: 1616
LTD Gold - Rating: 1616LTD Gold - Rating: 1616
 
Posts: 2327
Joined: Tue Oct 09, 2007 5:19 pm

Re: LTD Puzzle 2: Regular Pentagon

Postby reshefm on Sun Jun 22, 2008 2:23 pm

Ruby...

Code is hidden, SHOW
reshefm
Newbie
Newbie
LTD Bronze - Rating: 7
 
Posts: 2
Joined: Thu Jun 19, 2008 3:39 pm

The Winners

Postby damber on Fri Jun 27, 2008 3:04 pm

There are 2 types of winner - a "People's Champion" (the one with the most rating points across all their posts) and the LTD Admin's Champion (selected with our special formula....honest...well, maybe it's just the ones that the admins thought were particularly good :-))

So...

People's Champion: joint winners - AlexCuse and gmmastros both scoring 10 points each

LTD Admin's Champion: reshefm - for posting a nice ruby solution


Congratulations to all.. and good luck on next weeks puzzle :-)
a smile is worth a thousand kind words, so smile, it's easy! :-)


CODE: $5
WORKING CODE: $500
PROPERLY DESIGNED & WORKING CODE: Priceless
User avatar
damber
LTD Admin
LTD Admin
LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660
LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660LTD Silver - Rating: 660
 
Posts: 3134
Joined: Tue Oct 09, 2007 1:48 pm
Location: North Wales, UK
Unrated