回 帖 发 新 帖 刷新版面

主题:已知三角形A、B两点坐标、BC边长、∠BAC角度,求C点坐标

在QQ群里闲聊时看到的一个问题:已知三角形A、B两点坐标、BC边长、∠BAC角度,求C点坐标。
注:不一定是三角形,也就是说,角度可能是180、0 等等任何可能的值。
无聊自己试着写了下。才发现原来初中、高中的数学知识还是有用的[em1]
主要代码如下。还有一些小错误,
[code=vb]
Option Explicit
Private Type POINT
    x As Single
    y As Single
End Type

Private Function CalcAC(ByRef pA As POINT, ByRef pB As POINT, ByVal bc As Single, ByVal bac As Single) As Single
'//! 已知一个三角形的A、B两点坐标、BC边长、∠BAC,求另一边AC的长度
Dim ab As Single
Dim ac As Single
Const PI As Single = 3.1415926
ab = CalcDistance(pA, pB)

ac = Sqr(ab ^ 2 + bc ^ 2 - 2 * ab * bc * Cos(bac / 180 * PI))

CalcAC = ac
End Function
Private Sub DrawAxes()
    pic1.Cls
    
    pic1.Height = pic1.Width
    pic1.BackColor = vbBlack
    pic1.AutoRedraw = True
    pic1.Scale (-200, 200)-(200, -200)
    pic1.ForeColor = vbGreen
    pic1.DrawWidth = 1
    pic1.Line (-200, 0)-(200, 0)
    pic1.Line (190, 10)-(200, 0)
    pic1.Line (190, -10)-(200, 0)
    
    pic1.Line (0, -200)-(0, 200)
    pic1.Line (10, 190)-(0, 200)
    pic1.Line (-10, 190)-(0, 200)
End Sub

Private Sub Command1_Click()

Dim pA As POINT
Dim pB As POINT
Dim bc As Single
Dim bac As Single
Dim pt() As POINT

Dim r As Single
Dim n As Integer
Dim i As Integer

Dim result() As Single

Call DrawAxes

'//:测试
pA.x = 0
pA.y = 0
pB.x = 2
pB.y = 0
Debug.Print GetPoint(pA, 2, pB, 2, pt())
Debug.Print pt(0).x, pt(0).y
Debug.Print pt(1).x, pt(1).y
'Exit Sub

pA.x = txtAx.Text
pA.y = txtAy.Text

pB.x = txtBx.Text
pB.y = txtBy.Text

bc = txtBC.Text
bac = txtBAC.Text

    pic1.ForeColor = vbRed
    pic1.DrawWidth = 1
    pic1.POINT pA.x, pA.y
    pic1.POINT pB.x, pB.y
    pic1.Line (pA.x, pA.y)-(pB.x, pB.y)
    
    r = CalcAC(pA, pB, bc, bac)
    
    'Label5.Caption = r
    pic1.ForeColor = vbYellow
    pic1.Circle (pA.x, pA.y), r
    
    pic1.Circle (pB.x, pB.y), bc
    n = GetPoint(pA, r, pB, bc, pt())
    'Label5.Caption = Label5.Caption & "," & n
    
    pic1.ForeColor = vbMagenta
    For i = 0 To n - 1
        pic1.POINT pt(i).x, pt(i).y
        Debug.Print pt(i).x, pt(i).y
        If (CalcDistance(pt(i), pB) - bc) < 0.0000001 Then
            pic1.Line (pt(i).x, pt(i).y)-(pB.x, pB.y)
            pic1.Line (pt(i).x, pt(i).y)-(pA.x, pA.y)
            Label5.Caption = pt(i).x & "," & pt(i).y
            'Exit For
        Else
            Debug.Print "--------", bc, CalcDistance(pt(i), pB)
        End If
        
    Next
    
    pic1.ForeColor = vbGreen
    If n = 2 Then
        pic1.Line (pt(0).x, pt(0).y)-(pt(1).x, pt(1).y)
    End If
    
End Sub

Private Sub Form_Load()
Call DrawAxes
End Sub

Private Function GetPoint(ByRef pA As POINT, ByVal ra As Single, ByRef pB As POINT, ByVal rb As Single, ByRef pt() As POINT) As Long
'//! 获取两个圆的交点
'//! 返回值:交点的个数;交点的坐标通过pt()数组引用返回
'//! 参数:pa,pb两个圆的圆心坐标,ra,rb两个圆的半径
Dim ab As Single
Dim n As Integer
Dim r As Integer
Dim result() As Single
Dim a As Single
Dim b As Single
Dim c As Single
Dim i As Integer

ab = CalcDistance(pA, pB)
If ab > (ra + rb) Or ab < Abs(ra - rb) Then
    n = 0
ElseIf (ab < (ra + rb) And ab > Abs(ra - rb)) Then
    n = 2
ElseIf (ab = Abs(ra - rb) Or ab = (ra + rb)) Then
    n = 1
End If

Dim t As Single
t = ra ^ 2 - rb ^ 2 + pB.x ^ 2 - pA.x ^ 2 + pB.y ^ 2 - pA.y ^ 2
a = 1 + ((pB.y - pA.y) / (pB.x - pA.x)) ^ 2
b = -1 * (2 * ((pB.y - pA.y) / (pB.x - pA.x)) * ((t - (2 * pB.x - 2 * pA.x) * pA.x) / (2 * pB.x - 2 * pA.x)) + 2 * pA.y)
c = ((t - (2 * pB.x - 2 * pA.x) * pA.x) / (2 * pB.x - 2 * pA.x)) ^ 2 + pA.y ^ 2 - ra ^ 2

r = CalcFangCheng(a, b, c, result())
Debug.Assert r = n
If r > 0 Then
    ReDim pt(r - 1) As POINT
    For i = 0 To r - 1
        pt(i).y = result(i)
        pt(i).x = ((ra ^ 2 - rb ^ 2 + pB.x ^ 2 - pA.x ^ 2 + pB.y ^ 2 - pA.x ^ 2) - (2 * pB.y - 2 * pA.y) * pt(i).y) / (2 * pB.x - 2 * pA.x)
    Next
End If

GetPoint = n
End Function

Private Function CalcDistance(ByRef pA As POINT, ByRef pB As POINT) As Single
'//! 计算平面内两点的距离
    CalcDistance = Sqr((pB.x - pA.x) ^ 2 + (pB.y - pA.y) ^ 2)
End Function

Private Function CalcFangCheng(ByVal a As Single, ByVal b As Single, ByVal c As Single, ByRef result() As Single) As Long
'//! 解方程ax^2 + bx + c = 0
Dim n As Integer
Dim delta As Single

delta = b ^ 2 - 4 * a * c
If delta < 0 Then
    n = 0
ElseIf delta > 0 Then
    n = 2
    ReDim result(1) As Single
    result(0) = (b * (-1) + Sqr(delta)) / (2 * a)
    result(1) = (b * (-1) - Sqr(delta)) / (2 * a)
Else
    n = 1
    ReDim result(0) As Single
    result(0) = b * (-1) / (2 * a)
End If

CalcFangCheng = n
End Function
[/code]
[em1][em1][em1][em1]

回复列表 (共11个回复)

沙发

不错!
建议:
1、图案自动占据图片框的大部分(即自动缩放);
2、在图案中加注A、B、C三个角点和长度;
3、图片框的高度与窗体高度的配合要注意适应不同的标题栏高度。

板凳

哇,这么牛

3 楼

[url=http://www.cheapreplicawatche.co.uk/best-replica-uboat-watches-99.html]U-Boat Watches[/url]
[url=http://www.chanelhandbagsale.net/]Chanel Handbags[/url]
[url=http://www.chanelhandbagsale.net/]Replica Chanel[/url]
[url=http://www.chanelhandbagsale.net/]Chanel Replicas[/url]
[url=http://www.chanelhandbagsale.net/]Chanel on Sales[/url]
[url=http://www.cheapreplicawatche.co.uk/]replica watches[/url]
[url=http://www.cheapreplicawatche.co.uk/]replica watches UK[/url]
[url=http://www.cheapreplicawatche.co.uk/]Fake watches[/url]
[url=http://www.cheapreplicawatche.co.uk/]Rolex Replica[/url]
[url=http://www.cheapreplicawatche.co.uk/best-replica-bell-ross-watches-349.html]Bell & Ross Watches[/url]
[url=http://www.cheapreplicawatche.co.uk/best-replica-breitling-watches-312.html]Breitling Watches[/url]
[url=http://www.replicahause.org.uk]Replica Watches[/url]
[url=http://www.cheapreplicawatche.co.uk/best-replica-omega-watches-170.html]Omega Watches[/url]
[url=http://www.cheapreplicawatche.co.uk/best-replica-panerai-watches-292.html]Panerai Watches[/url]
[url=http://www.cheapreplicawatche.co.uk/best-replica-patek-philippe-watches-415.html]Patek Philippe Watches[/url]
[url=http://www.cheapreplicawatche.co.uk/best-replica-rolex-watches-143.html]Rolex watches[/url]
[url=http://www.cheapreplicawatche.co.uk/best-replica-tag-heuer-watches-166.html]Tag Heuer Watches[/url]

4 楼

NOT all that Mrs. Bennet, however, with the assistance of [url=http://www.timberlandforyou.com/]mens timberland boots[/url] her five daughters, could ask on the subject was sufficient to draw from her husband any satisfactory description of Mr. Bingley. They attacked him in various ways; with [url=http://www.timberlandforyou.com/]timberland 6 inch boots[/url] barefaced questions, ingenious suppositions, and distant surmises; but he eluded the skill of them all; and they were at last obliged to accept the second-hand intelligence of their [url=http://www.timberlandforyou.com/]timberland roll top[/url] neighbour Lady Lucas. Her report was highly favourable. Sir William had been delighted with him. He was quite young, wonderfully [url=http://www.timberlandforyou.com/]timberland roll top boot[/url] handsome, extremely agreeable, and, to crown the whole, he meant to be at the next assembly with a large party. Nothing could be more delightful! To be fond of dancing was a certain step towards [url=http://www.timberlandforyou.com/]timberland roll top boot[/url] falling in love; and very lively hopes of Mr. Bingley's heart were entertained.;If I can but see one of my daughters happily settled at Netherfield,; said Mrs. Bennet to her husband, ;and all the others [url=http://www.timberlandforyou.com/]Womens 14-Inch Premium Waterproof Boots[/url] equally well married, I shall have nothing to wish for.;In a few days Mr. Bingley returned Mr. Bennet's visit, and sat about ten minutes with him in his library. He had entertained [url=http://www.timberlandforyou.com/]shop timberland boots[/url] hopes of being admitted to a sight of the young ladies, of whose beauty he had heard much; but he saw only the father. The ladies were somewhat more fortunate, for they had the advantage [url=http://www.timberlandforyou.com/]timberland men boots[/url] of ascertaining, from an upper window, that he wore a blue coat and rode a black horse.An invitation to dinner was soon afterwards dispatched; and already had Mrs. Bennet planned the courses that were [url=http://www.timberlandforyou.com/]timberlands boots[/url] to do credit to her housekeeping, when an answer arrived which deferred it all. Mr. Bingley was obliged to be in town the following day, and consequently unable to accept the honour of their [url=http://www.timberlandforyou.com/]timberland boots on sale[/url] invitation, c. Mrs. Bennet was quite disconcerted. She could not imagine what business he could have in town so soon after his arrival in Hertfordshire; and she began to fear that he might [url=http://www.timberlandforyou.com/]cheap timberland boots[/url] be always flying about from one place to another, and never settled at Netherfield as he ought to be. Lady Lucas quieted her fears a little by starting the idea of his being gone to London only to [url=http://www.timberlandforyou.com/]timberland boots on sale[/url] get a large party for the ball; and a report soon followed that Mr. Bingley was to bring twelve ladies and seven gentlemen with him [url=http://www.timberlandforyou.com/]womens timberland boots[/url] to the assembly.
[url=http://www.timberlandforyou.com/]timberland 14 inch boots[/url] 
[url=http://www.timberlandforyou.com/]timberland working boots[/url] 
[url=http://www.timberlandforyou.com/]mens timberland boots[/url] zxj

5 楼


输入 A:(0,100), B:(100,0),<BAC = 45, BC=150
结果明显不对

6 楼

令A点坐标为(0,0),B点坐标为(0,b),∠BAC=α,BC=m
则直线AC的方程为                Y=Xarctgα
以B为圆心,m为半径的圆方程为    (x-b)^2+Y^2=m
这两个方程的解即C点坐标。按此原理编程很容易。

7 楼

[url=http://www.sincen.cn]南京到北京旅游[/url] [url=http://www.naliniu.com]南京康辉旅行社[/url]

8 楼

Russian President Dmitry Medvedev on Sunday [url=http://www.soccercleatsonlines.com/adidas-soccer-cleats-adidas-adipower-predator-trx-fg-c-1_29.html]adidas Adipower predator[/url] ordered an investigation into the allegations of electoral fraud during last weeks parliamentary vote. The announcement came a day after tens of thousands of people rallied in Moscow and other cities to demand the December 4 polls [url=http://www.cheaptimberlandswholesale.com/]cheap timberlands[/url] won by Prime Minister Vladimir Putins ruling United Russia party be annulled and rerun. In a post on the social media site Facebook, Mr. Medvedev said that although he does not agree with any slogans or speeches made at the rallies, he has given [url=http://www.soccercleatcheap.com/]cheap soccer cleats[/url] instructions to check all information from polling station regarding compliance with the election laws. Within minutes of his statement, Mr. Medvedev had received over 1,000 comments on his Facebook site, most of them angry and some [url=http://www.timberlandoutletonline.com/]timberland outlet online[/url] disrespectful. The Occupy London protest site reached its 60th day Monday, running longer than its counterpart in New York did before it was dismantled. It now occupies three sites across the City of London - a cathedral courtyard, a square [url=http://www.soccercleatsonlines.com/adidas-soccer-cleats-adidas-f50-adizero-micoach-fg-c-1_9.html]adidas adizero f50[/url] and a building. One of the sites even has an art gallery. But with growth has come rivalry between the two, with criticism that some American protesters who have decamped to London from New York are too reliant on their creature [url=http://www.cheaptimberlandswholesale.com/mens-timberland-roll-top-boots-c-3.html]timberland boots on sale[/url] comforts. The U.S. economy has recently showed signs of improvement with the unemployment rate dropping from nine percent to 8.6 percent but it remains far above a normal traditional rate of four or five percent. The jobless rate [url=http://www.soccercleatcheap.com/nike-mercurial-glide-iii-ag-green-black-p-289.html]nike mercurial green[/url] is seen as a major factor in whether Mr. Obama can win re-election to another four-year term next November. The president once again called on Congress to approve his nominee, Richard Cordray, to head a new consumer [url=http://www.timberlandoutletonline.com/mens-timberland-roll-top-boots-wheat-p-50.html]timberland roll top boots[/url] protection agency. U.S. President Barack Obama is pressing Republicans in Congress to approve his nominee Richard Cordray to head the first ever consumer guardian agency. During his weekly address Saturday, Obama urged lawmakers to give [url=http://www.soccercleatsonlines.com/nike-soccer-cleats-nike-mercurial-vapor-viii-fg-c-41_64.html]nike mercurial vapor fg[/url] Americans the protection they need from being taken advantage of by mortgage lenders, payday lenders and debt collectors. The president says many people on Wall Street have made a lot money taking advantage of consumers. He is appealing [url=http://www.cheaptimberlandswholesale.com/]timberland for sale[/url] to legislators to give Americans an advocate he says will protect them from unscrupulous practices. Protesters came out across the worlds largest country to demand clean elections and to say what, only one week ago, [url=http://www.soccercleatcheap.com/nike-soccer-cleats-nike-mercurial-victory-iv-ag-c-41_73.html]nike mercurial victory iv[/url] was unsayable. Russia Without Putin was the favorite chant of thousands of demonstrators who marched within earshot of the Kremlin in the largest pro-democracy demonstration since Vladimir Putin came to power in 2000. From Vladivostok on the Pacific [url=http://www.timberlandoutletonline.com/mens-timberland-6-inch-premium-boots-olive-green-p-112.html]timberland boots for men[/url] Coast to Kaliningrad on the Baltic.CF

9 楼


Where you can order new 2012 style [url=http://www.timberlandbootshiking.com/timberland-roll-top-boots-c-9.html]Timberland Roll Top Boots[/url] for men & women size.Why not come to our website.You can find more
[url=http://www.timberlandbootshiking.com/timberland-chukka-boots-c-6.html]Timberland Chukka Boots[/url] high quality,factory price.
If you are looking cheapest [url=http://www.timberlandbootshiking.com/timberland-6-inch-boots-c-2.html]Timberland 6 Inch Boots[/url], the style of 6 inch timberland boots more durable,waterproof,comfortable.

10 楼

好文章。总是支持一下的

我来回复

您尚未登录,请登录后再回复。点此登录或注册