Simple math practice

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
Marcus Aseth
Prole
Posts: 14
Joined: Wed Apr 05, 2017 11:56 am

Simple math practice

Post by Marcus Aseth »

Since I suck at math I thought I could make myself a tool to help me visualize it and see relations between numbers, practice some very useful math stuff needed for game development and such.

So I started today trying to visualize the distance formula x^2 + y^2 = c^2

Program below, feel free to try and break it :joker:
keys:
left mouse button press = add point to the grid
left mouse button drag = drag around selected point
numpad+ = zoom (enlarge) the grid
numpad- = zoom (shrinken) the grid
F1 = switch between fullscreen and windowed

After adding a second point, the next point you select will display the distance from the next point in the info pannel on the right :awesome:
MathPractice.love
(7.74 KiB) Downloaded 170 times
User avatar
Marcus Aseth
Prole
Posts: 14
Joined: Wed Apr 05, 2017 11:56 am

Re: Simple math practice

Post by Marcus Aseth »

I was trying to add a dashed line and I got this (img below)
This is the code (code below)
There is any easy way for me to add a moving animation to the dashes in that code? Like if they are flowing from one point to the next :crazy:
(the points passed to this function are ordered by index, and when the last index is the starting point the end point is index 1, it goes in a circle)

Code: Select all

function dashedLine(startX, startY, endX, endY)

  --dashed line segments dinamically increased based on the 2 points distance
  local lineDivisions = 1.5 * round(findDistance({ x = startX, y = startY }, { x = endX, y = endY }))
  --split the distance between the 2 points into N segments, distX/distY are 1 segment lenght
  local distX = math.abs(endX - startX) / lineDivisions
  local distY = math.abs(endY - startY) / lineDivisions
  
  --set on which direction the segment should go
  distX = startX < endX and distX or -distX
  distY = startY < endY and distY or -distY
 
  --offset to center the dashed line (not truly working though)
  local offsetX = (startX + distX / 4)
  local offsetY = (startY + distY / 4)

  for i = 0, lineDivisions - 1 do
    local currX = offsetX + distX * i
    local currY = offsetY + distY * i
    local nextX = currX + distX / 2.5
    local nextY = currY + distY / 2.5
    love.graphics.line(currX, currY, nextX, nextY)
  end
end



Image
User avatar
OnACoffeeBreak
Prole
Posts: 28
Joined: Tue Apr 11, 2017 11:19 am

Re: Simple math practice

Post by OnACoffeeBreak »

I'm new to LOVE myself... I think it's neat to use it to visualize trigonometric problems, and I really like how your demo looks and feels.

If I understand correctly, you're using the Pythagorean theorem to calculate the distance between two points. I wonder if it would help to present an interactive visual proof of the theorem. Maybe one of these will work:

https://math.stackexchange.com/question ... as-theorem

https://math.stackexchange.com/question ... an-theorem

https://math.stackexchange.com/question ... m-you-know
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Simple math practice

Post by raidho36 »

One fantastic thing about math is that you don't need to intrinsically understand it or know what representations it has, you just need to know how it works and do equations right. Things like quaternions and matrices and whatnot.
Post Reply

Who is online

Users browsing this forum: No registered users and 44 guests