English 中文(简体)
Math/programming: 如何使物体偏离一条线的道路
原标题:Math/programming: How to make an object go through a path made from a line

现在,我是在五B6号文件中这样做的,但我不认为这是我做的,是不是这样做的? 我认为,它必须处理数学问题。

这里的问题是,看一看这方面的情况。

“entergraph

As you can see in this image, there is a black line and a grey circle. I want the circle to move from the bottom left to the bottom right, but I also want it to stay along the path of the line so it reaches our second picture like this:

“entergraph

Now how can I accomplish this? Again, using VB6.

最佳回答

Ok, I don t know VBA6 but, since you said:

I don t think it matters what I do it in

我将提出一个通用的解决办法,涉及你们的圈子和线端点。

这条线可视为病媒:

 (line.x2-line.x1, line.y2-line.y1)

You don t need to write this in your program or anything just saying it is a vector.

What you do need to is get the magnitude of the vector and assign it to a variable:

unitSize = sqrt((line.x2-line.x1)^2 + (line.y2-line.y1)^2)

如今,它已成为病媒的单位组成部分,并具有单独的构成部分:

unitX = (line.x2-line.x1)/unitSize
unitY = (line.y2-line.y1)/unitSize

Now how ever you update the circle:

do {
    circle.x = circle.x + unitX * incrementSize //incrementSize scales how big the movement is assign it to whatever you seem fit.
    circle.y = circle.y + unitY * incrementSize
until (circle.x >= line.x2) //Or <= line.x2 depends which way you are going.

Hopefully this helps.

问题回答

我认为,实现这一点有多种途径,但这是我所想的第一个途径。 它作出一些假设......好像您的行文朝着积极的方向发展,它始于0。 如果其中任何一个情况都属实,那么你会再写更多的文字来加以调整。

=================================================

    Psuedocode:
     To track current coordinates of the center of the circle
    dim x as float, y as float
    x = 0: y = 0

     Coordinates for the line
    dim x1 as float, y1 as float, x2 as float, y2 as float
    x1=0: y1=0: x2=50: y2=75

     How much we re going to move the circle at a time
    dim xStep as float, yStep as float, stepSize as float
    stepSize = 100
    xStep = x2 / stepSize
    yStep = y2 / stepSize

    Do
        Draw circle here with x, y for coordinates
       x = x + xStep
       y = y + yStep
    Loop Until xStep > x2




相关问题
Prevent windows from queuing shellexecute requests

Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL I want google....

Why is My Loop Only Deleting One File?

Using VB6 In a folder, i have n number of files, i want to delete a 0 kb files code Dim filename5 As String filename5 = Dir$(txtsourcedatabasefile & "*_*", vbDirectory) MsgBox filename5 Do ...

How to check the filesize?

Using VB6 I have the text file with different sizes, so i want to delete the file where filesize = 0 kb. How to make a vb6 code for deleting the 0 kb files. Need vb6 code Help

File Rename problem?

I m using VB6 and I have a folder where I have n number of files. I want to change the file extension to .txt. I used the code below to change the extension of all .fin files to .txt. Dim filename1 ...

Error 20728-F while in using Crystal Reports in VB6

I m using Crystal Reports in my VB6 project, but I m facing error while loading the report in crystalreport1.action=1; Please give me some solution for this problem. It is showing the error as Error ...

DllRegisterServer entry point was not found

When running my vb6 application I am getting error like, runtime error 53 : file not found: rscomclNoMsg.dll then i tried to register that dll from cmd line using regsvr32. Then I am getting ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签