Re: weird problem



Alef.Veld@xxxxxxxxx wrote:
On Jan 24, 10:55 pm, j...@xxxxxxxxxxx (Jens Thoms Toerring) wrote:
So I am lead to assume that '(grid_size - grid_start)' is the size of
a square grid and you want to compare the number of points on that
grid to the number of 'collisions'. In that case you need to round
the result of squaring the grid size to the nearest int,

You're right. This might actually be my problem then. Would a cast
suffice or do i have to manually round this off somehow with a
conversion specifier.

A conversion specifier only can be used in printf() etc. And a cast
alone won't do since it simply cuts off everything after the decimal
point. But that won't get you 144 from 143.99999999. You need to
round to the nearest integer, e.g. by using

( int ) ( d < 0.0 ? ceil( d - 0.5 ) : floor( d + 0.5 ) );

where d is your float or double - or, since you are rounding
the square of a float, which is always positive,

( int ) floor( d + 0.5 )

will do.

BTW, you also have an off-by-one (fence-post) error: if the size
of the grid is (a - b) then the number of points on th grid is
(a - b + 1) * (a - b + 1).

Ah. I see that without proper code this is getting confusing for the
both of us :-). I will see if i can supply both 2 functions which cause
my troubles.

Yes, please do that;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.



Relevant Pages

  • Re: A new line of sight algorithm
    ... and I think it fits in perfectly with the geometry of Roguelikes. ... the line as a path along the grid. ... But things are different if you start with a grid of diamonds ... checkerboard square grid turned 45 degrees.) ...
    (rec.games.roguelike.development)
  • Re: Ideas, Making a graphical grid look like ISO view
    ... I'm drawing a square grid and I have mouse events that return ... SimCity 3K actually used th isometric view to allow them to bump up the graphical complexity of their engine. ... Normally, when you pan the camera in a 3D environment, you have to re-render, because the parallax effect will cause you to be able to see parts of the building which were previously invisible to you. ...
    (comp.lang.java.programmer)
  • Re: square grid generation
    ... >> Simone wrote: ... >>>i'm trying to generate a square grid for finite difference ... from this image I must generate a square grid ...
    (comp.soft-sys.matlab)
  • Enigma 1452 - Crossed lines
    ... I made a much larger square grid with lines ... I calculated the number of rectangles which ... What was the size of my original grid before ...
    (rec.puzzles)
  • Re: Mapping a square grid to a rectangular grid
    ... >the square grid to a grid point of the rectangular grid. ... >This mapping should be injective ...
    (sci.math)