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

Function bcosPoints

recipes/Python/Draw Sine Function in PDF/drawSines.py:66–100  ·  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 cosine function graph from 0 to 2*pi.

(pb, pe)

Source from the content-addressed store, hash-verified

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
68 from (0,0) to (2*pi, 0), respectively, in the user's coordinate system.
69 The returned points can be used to draw up to four Bezier curves for
70 the complete cosine function graph from 0 to 2*pi.
71 """
72 f = abs(pe - pb) * 0.5 / math.pi # represents the unit
73 alfa = 5.34295228e-01
74 beta = 1.01474288e+00
75 # adjust for either horizontal or vertical
76 if pb.y == pe.y:
77 y_ampl = (0, f)
78 y_alfa = (0, f * alfa)
79 y_beta = (0, f * beta)
80 elif pb.x == pe.x:
81 y_ampl = (-f, 0)
82 y_alfa = (-f * alfa, 0)
83 y_beta = (-f * beta, 0)
84 else:
85 raise ValueError("can only draw horizontal or vertical")
86
87 p0 = pb - y_ampl
88 p4 = pe - y_ampl
89 p1 = pb + (pe - pb)*0.25
90 p2 = pb + (pe - pb)*0.5 + y_ampl
91 p3 = pb + (pe - pb)*0.75
92 k1 = pb + (pe - pb)*(1./12.) - y_beta
93 k2 = pb + (pe - pb)*(2./12.) - y_alfa
94 k3 = pb + (pe - pb)*(4./12.) + y_alfa
95 k4 = pb + (pe - pb)*(5./12.) + y_beta
96 k5 = pb + (pe - pb)*(7./12.) + y_beta
97 k6 = pb + (pe - pb)*(8./12.) + y_alfa
98 k7 = pb + (pe - pb)*(10./12.) - y_alfa
99 k8 = pb + (pe - pb)*(11./12.) - y_beta
100 return p0, k1, k2, p1, k3, k4, p2, k5, k6, p3, k7, k8, p4
101
102if __name__ == "__main__":
103 from fitz.utils import getColor

Callers 1

drawSines.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected