MCPcopy Create free account
hub / github.com/ActiveState/code / bsinPoints

Function bsinPoints

recipes/Python/Draw Sine Function in PDF/drawSines.py:30–64  ·  view source on GitHub ↗

Return Bezier control points, when pb and pe stand for a full period from (0,0) to (2*pi, 0), respectively, in the user's coordinate system. The returned points can be used to draw up to four Bezier curves for the complete sine function graph from 0 to 2*pi.

(pb, pe)

Source from the content-addressed store, hash-verified

28
29"""
30def bsinPoints(pb, pe):
31 """Return Bezier control points, when pb and pe stand for a full period
32 from (0,0) to (2*pi, 0), respectively, in the user's coordinate system.
33 The returned points can be used to draw up to four Bezier curves for
34 the complete sine function graph from 0 to 2*pi.
35 """
36 f = abs(pe - pb) * 0.5 / math.pi # represents the unit
37 alfa = 5.34295228e-01
38 beta = 1.01474288e+00
39 # adjust for either horizontal or vertical
40 if pb.y == pe.y:
41 y_ampl = (0, f)
42 y_alfa = (0, f * alfa)
43 y_beta = (0, f * beta)
44 elif pb.x == pe.x:
45 y_ampl = (-f, 0)
46 y_alfa = (-f * alfa, 0)
47 y_beta = (-f * beta, 0)
48 else:
49 raise ValueError("can only draw horizontal or vertical")
50
51 p0 = pb
52 p4 = pe
53 p1 = pb + (pe - pb)*0.25 - y_ampl
54 p2 = pb + (pe - pb)*0.5
55 p3 = pb + (pe - pb)*0.75 + y_ampl
56 k1 = pb + (pe - pb)*(1./12.) - y_alfa
57 k2 = pb + (pe - pb)*(2./12.) - y_beta
58 k3 = pb + (pe - pb)*(4./12.) - y_beta
59 k4 = pb + (pe - pb)*(5./12.) - y_alfa
60 k5 = pb + (pe - pb)*(7./12.) + y_alfa
61 k6 = pb + (pe - pb)*(8./12.) + y_beta
62 k7 = pb + (pe - pb)*(10./12.) + y_beta
63 k8 = pb + (pe - pb)*(11./12.) + y_alfa
64 return p0, k1, k2, p1, k3, k4, p2, k5, k6, p3, k7, k8, p4
65
66def bcosPoints(pb, pe):
67 """Return Bezier control points, when pb and pe stand for a full period

Callers 1

drawSines.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected