Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 WhatDotColour : MathDistancePointLine
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Guest




PostPosted: Mon Jun 05, 2006 10:48 pm   Post subject: WhatDotColour : MathDistancePointLine

I decided to make a program to test whatdotcolour's collision detection. But I hear people bashing whatdotcolour sometimes and saying learn Math.DistancePointLine (kinda like the main loops and processes). But I looked in the Turing help menu, and that always confuses me. I usually learn by looking at others code and figuring out how it works on my own. Will someone convert this using Math.DistancePointLine. I did look at the Tutorial, but I dont really understand it. Besides, I want a direct comparison between my program and Math.DistancePointLine.

code:

View.Set ("graphics,offscreenonly")
Mouse.ButtonChoose ("multibutton")
var xMouse, yMouse, button : int
var lifter, yLine, x, y := 1
var xBall, yBall := 200
var rad := 10
var line : array 1 .. 2 of int := init (yellow, white)

loop
    Mouse.Where (xMouse, yMouse, button)

    if (rad = 3) then
        rad += 1
    end if

    if (button = 1) then
        rad += 1
    elsif (button = 10) then
        xBall := xMouse
        yBall := yMouse
    elsif (button = 100) then
        rad -= 1
    end if

    if whatdotcolour (xBall + rad, yBall + rad) = line (1) or
            whatdotcolour (xBall + rad, yBall + rad) = line (2) or
            whatdotcolour (xBall + rad, yBall - rad) = line (2) or
            whatdotcolour (xBall + rad, yBall - rad) = line (2) then
        x := -x
        y := -y
    end if

    drawfillbox (0, 0, maxx, maxy, black)
    drawline (0, 200, maxx, lifter, line (1))
    drawline (maxx, 200, 0, lifter, line (2))
    drawfilloval (xBall, yBall, rad, rad, white)
    View.Update

    lifter += yLine
    xBall += x
    yBall += y

    if (lifter = maxy) then
        yLine := -yLine
    elsif (lifter = 0) then
        yLine := -yLine
    end if

    if (xBall + rad = maxx) then
        x := -x
    elsif (xBall - rad = 0) then
        x := -x
    end if
    if (yBall + rad = maxy) then
        y := -y
    elsif (yBall - rad = 0) then
        y := -y
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
TheOneTrueGod




PostPosted: Tue Jun 06, 2006 6:53 am   Post subject: (No subject)

Turing F10 wrote:

Math.DistancePointLine (xp, yp, x1, y1, x2, y2 : real) : real


(xp,yp) is the point that you are checking (Math.DistancePointLine

(x1,y1) is the first point of the line

(x2,y2) is the second point of the line

Now, as it should be obvious, if you have one point, and one line, there are infinitely many ways that you can measure the distance between those two. (Unless the line isn't a line, and is just a point. But then it isn't a line Razz) So, what mathematicians sp? decided, was that you should try and find the shortest distance between the line and the point. Now, just look at the source code that the Turing F10 gave you (explicitly for your purposes)

code:

% The "Math.DistancePointLine" program.
var xp, yp, x1, y1, x2, y2 : int
loop
    const RADIUS : int := 100
    xp := Rand.Int (RADIUS, maxx - RADIUS)
    yp := Rand.Int (RADIUS, maxy - RADIUS)
    x1 := Rand.Int (0, maxx)
    y1 := Rand.Int (0, maxy)
    x2 := Rand.Int (0, maxx)
    y2 := Rand.Int (0, maxy)
    cls
    Draw.FillOval (xp, yp, RADIUS, RADIUS, brightred)
    Draw.Line (x1, y1, x2, y2, blue)
    if Math.DistancePointLine (xp, yp, x1, y1, x2, y2) < RADIUS then
        put "The circle touches the line"
    else
        put "The circle does not touch the line"
    end if
    delay (2000)
    exit when hasch
end loop


^^^^^^^^^^^^^^^^^
That is copied directly from the F10 help menu. If you ever do not understand how a command works, just look at the F10 menu. It gives you basically anything you need, from source code to how to use the command written out in words.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: