### Author Topic: Anyone got code for a 3D(or flat) Hexagon?  (Read 555 times)

#### JohnnyB

• Mc. Print
• • Posts: 37 ##### Anyone got code for a 3D(or flat) Hexagon?
« on: 2019-Aug-13 »
Just askin #### SnooPI ##### Re: Anyone got code for a 3D(or flat) Hexagon?
« Reply #1 on: 2019-Oct-14 »
A 3D hexagon (or hexagonal prism) is just a particular cylinder.
If you use this function with slices=6, you normally get a hexagonal prism (I have not tested).

CreateCylinder(0,  16, 16, 16,  6, 1,  RGB(255, 0, 0))

Code: (glbasic) [Select]
`FUNCTION CreateCylinder: num, baseRadius, topRadius, height, slices, stacks, colLOCAL da, r, dr, dz, x, y, z, i, jLOCAL x1, y1, x2, y2 da = 360 / slices dr = (topRadius-baseRadius) / stacks dz = height / stacks X_AUTONORMALS 2 X_OBJSTART num FOR i=0 TO slices-1 x1 = COS(i*da) y1 = SIN(i*da) x2 = COS((i+1)*da) y2 = SIN((i+1)*da) z = 0 r = baseRadius // Bottom lid IF baseRadius>0 X_OBJADDVERTEX 0, 0, 0,  .5, .5, col X_OBJADDVERTEX x1*r, y1*r, 0, x1/2+.5, y1/2+.5, col X_OBJADDVERTEX x2*r, y2*r, 0, x2/2+.5, y2/2+.5, col X_OBJNEWGROUP ENDIF // side FOR j=0 TO stacks X_OBJADDVERTEX x2*r, y2*r, z, (i+1)/slices,  j/stacks, col X_OBJADDVERTEX x1*r, y1*r, z,  i   /slices,  j/stacks, col z = z+dz r = r+dr NEXT // Top lid IF topRadius>0 X_OBJNEWGROUP X_OBJADDVERTEX x2*r, y2*r, height, x2/2+.5, y2/2+.5, col X_OBJADDVERTEX x1*r, y1*r, height, x1/2+.5, y1/2+.5, col X_OBJADDVERTEX 0, 0, height,  .5, .5, col ENDIF X_OBJNEWGROUP NEXT X_OBJENDENDFUNCTION`
{"ft_lang_label":"__label__en","ft_lang_prob":0.5036612,"math_prob":0.98123485,"size":1158,"snap":"2020-45-2020-50","text_gpt3_token_len":508,"char_repetition_ratio":0.17677642,"word_repetition_ratio":0.0,"special_character_ratio":0.39723662,"punctuation_ratio":0.26384366,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9901644,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,4,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-02T00:43:24Z\",\"WARC-Record-ID\":\"<urn:uuid:25eec537-2bab-4e99-bb7d-f9c6970bfc39>\",\"Content-Length\":\"29709\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:93eccbf5-218c-42cd-a1eb-b11d9801b17b>\",\"WARC-Concurrent-To\":\"<urn:uuid:8fd00602-4271-438c-b573-cfc188b8a334>\",\"WARC-IP-Address\":\"81.169.145.88\",\"WARC-Target-URI\":\"https://www.glbasic.com/forum/index.php?topic=11330.msg99618\",\"WARC-Payload-Digest\":\"sha1:G53GGWCNQ7SE3P3AXXRMQ5XZDAP466PQ\",\"WARC-Block-Digest\":\"sha1:6LI4NLK77XMU6OZXO3572IOYP622WW3I\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141685797.79_warc_CC-MAIN-20201201231155-20201202021155-00531.warc.gz\"}"}