Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6707615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:39:38+00:00 2026-05-26T07:39:38+00:00

EDIT: This is a library bug. I reported it to the HOpenGL mail list.

  • 0

EDIT: This is a library bug. I reported it to the HOpenGL mail list.

I use 9-point rectangular method to represent a circle/ellipse as a NURBS.

The points are p1, p2, ..., p9, p9 = p1. They lay as shown:

y2 | p2 p3 p4
y1 | p1    p5
y0 | p8 p7 p6
-------------
   | x0 x1 x2

x1 = (x0 + x2) / 2
y1 = (y0 + y2) / 2

I.e. p1 = (x0, y1), p2 = (x0, y2) and so on.

And weights are:

  • 1 for middle points (p1,p3,p5,p7)
  • sqrt(0.5) for corner points (p2,p4,p6,p8)

I applied weights as homogeneous coordinates, using two ways:

  • right – (x,y) with weight w becomes Vertex4 (w*x) (w*y) 0 w
  • wrong – it becomes Vertex4 x y 0 w

The results (right first, wrong second, sorry if they are too big):
first
second

You see, both are not proper circles (though the second looks nice) and I can’t understand why.

Here follows the code, based on Lines.hs from GLUT examples:

import System.Exit ( exitWith, ExitCode(ExitSuccess) )
import Graphics.UI.GLUT
import Foreign.Marshal.Array
import Graphics.Rendering.OpenGL.GLU.NURBS

myInit :: IO ()
myInit = do
   clearColor $= Color4 0 0 0 0

display :: DisplayCallback
display = do
  clear [ ColorBuffer, DepthBuffer ]
  color (Color3 1.0 1.0 1.0 :: Color3 GLfloat)

  withNURBSObj () $ \nurbsObj -> do
    nurbsBeginEndCurve nurbsObj $
      withArrayLen knots $ \nKnots knots ->
        withArray controls $ \controls -> do
          nurbsCurve nurbsObj (fromIntegral nKnots) knots stride controls order

  flush

  where
    order = 3
    stride = 4 -- number of floats in Vertex
    controls = zipWith mkControl points weights
    mkControl (x, y) w = Vertex4 (x*w) (y*w) 0 w
    -- mkControl (x, y) w = Vertex4 x y 0 w
    knots = [0, 0, 0, 0.25, 0.25, 0.5, 0.5, 0.75, 0.75, 1, 1, 1]
    weights = let a = sqrt 0.5 in [1, a, 1, a, 1, a, 1, a, 1]
    points = [
      (x0, y1), (x0, y2), (x1, y2),
      (x2, y2), (x2, y1), (x2, y0),
      (x1, y0), (x0, y0), (x0, y1)
      ]

    y1 = (y0 + y2) / 2
    x1 = (x0 + x2) / 2
    (x0, x2) = (50, 450)
    (y0, y2) = (x0, x2)

reshape :: ReshapeCallback
reshape size@(Size w h) = do
   viewport $= (Position 0 0, size)
   matrixMode $= Projection
   loadIdentity
   ortho2D 0 (fromIntegral w) 0 (fromIntegral h)
   -- the following line is not in the original example, but it's good style...
   matrixMode $= Modelview 0

keyboard :: KeyboardMouseCallback
keyboard (Char '\27') Down _ _ = exitWith ExitSuccess
keyboard _ _ _ _ = return ()

--  Request double buffer display mode.
--  Register mouse input callback functions
main :: IO ()
main = do
   (progName, _args) <- getArgsAndInitialize
   initialDisplayMode $= [ SingleBuffered, RGBMode ]
   initialWindowSize $= Size 500 500
   initialWindowPosition $= Position 100 100
   createWindow "Test"
   myInit
   displayCallback $= display
   reshapeCallback $= Just reshape
   keyboardMouseCallback $= Just keyboard
   mainLoop

EDIT: I rechecked coefficients several times, and before rectangular representation I used 7-point triangle method, and there were very similar distortions. So it shall not be a problem with concrete representation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:39:38+00:00Added an answer on May 26, 2026 at 7:39 am

    Okay, with my first answer I had a momentary lapse of reason. Anyway, you don’t have a bug in your code at all: If I compile and execute the code given I get this:

    NURBS circle

    I suspect, something in your Haskell installation is broken.

    EDIT due to comment:

    Now that’s odd…

    I’m using Gentoo, so my system offers the Haskell OpenGL modules through the Portage system. Thus I get this:

    loki ~ # for p in OpenGL OpenGLRaw GLURaw; do ghc-pkg latest $p; done
    OpenGL-2.2.1.1
    ghc-pkg: cannot find package OpenGLRaw
    ghc-pkg: cannot find package GLURaw
    

    So I installed the OpenGL and GLUT modules with cabal into my homedir:

    datenwolf@loki ~ $  for p in OpenGL OpenGLRaw GLURaw; do ghc-pkg latest $p; done
    OpenGL-2.4.0.1
    OpenGLRaw-1.1.0.1
    GLURaw-1.1.0.0
    

    And with those installed I can reproduce your first picture!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: This code is fine. I found a logic bug somewhere that doesn't exist
Edit: This is a confirmed bug in jQuery 1.3.1. It is fixed in jQuery
EDIT: This was an old bug long since fixed in Scala 2.8 and later
I have built a multilingual website with CodeIgniter using this library: http://codeigniter.com/wiki/URI_Language_Identifier/ I use
EDIT: It looks like a bug in AIR. I've reported it here: https://bugbase.adobe.com/index.cfm?event=bug&id=2955444 please
I suspect this is a bug in library(foreign) but I am not sure. When
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.